I am working on a math app and need to output exponents to the screen.
I've found that this code will work:
NSLog(#"x\u2070 x\u00B9 x\u00B2 x\u00B3 x\u2074 x\u2075 x\u2076 x\u2077 x\u2078 x\u2079");
it displays: x⁰ x¹ x² x³ x⁴ x⁵ x⁶ x⁷ x⁸ x⁹
This also works:
NSString *testString = #"8.33x10\u00B3";
NSLog(#"test string: %#", testString);
it displays: test string: 8.33x10³
Even setting it to a label displays correctly on the iPhone screen:
NSString *testString = #"8.33x10\u00B3";
Answer1Label.text = testString;
However, when I pull the string from a .plist that says "8.33x10\u00B3" and display it on the screen, it just shows up as "8.33x10\u00B3" instead of 8.33x10³
Is there an additional character I need to put in front of the \u00B3 to get it to recognize?
Thanks for your help!
The \uXXXX is converted into unicode at compile time, so you wouldn't expect that to be magically converted by reading a .plist.
Try opening the the plist file in Xcode in "text mode" (right click your plist file, Open As -> Plan Text File), then edit the desired string to contain the special characters by using text of the form:
⁰
rather than the usual \u2070 you've been using in-code. Then if you save your plist, close it, and open it again by double clicking, you'll see the usual plist editor view and it will contain your special characters.
Alternatively, consider using OS X's character viewer (aka character palette) to input the text directly into the plist editor in Xcode. More info.
Related
The problem I have can be re-produced by pasting this code into PyCharm:
chinese = [u'这', u'是', u'一', u'些', u'中', u'文']
print chinese
When you set a breakpoint at the print line and start debugging, you could see tha the variable chinese in the watch window is displayed as
[u'\u8fd9', u'\u662f', u'\u4e00', u'\u4e9b', u'\u4e2d', u'\u6587']`
However, I expect it to be
[u'这', u'是', u'一', u'些', u'中', u'文']
Unless I double click this variable, it does not show the characters directly.
How can I solve this problem?
I would like to display a unicode character (the speaker symbol U+1F50A) in label.
Is it possible to enter this symbol in Interface Builder?
Yes, you can click "Edit" > "Special Characters…" — there you can find all unicode characters (including the emoji) and copy/paste them where you set the label text in Interface Builder.
EDIT:
In Xcode 6 it's "Edit" > "Emoji & Characters"
Xcode 7+: "Edit" > "Emoji & Symbols"
For those who tried doing it programmatically, but failed, just use this:
label.text = #"\U0001F50A";
Do it programmatically.
Declare an IBOutlet for the Label, with the means of NSString type:
// UTF-8 Hexadecimal Encoding
NSString *myString = [NSString stringWithUTF8String:"0xF09F948A"];
myLabel.text = myString;
Also, take a look at this question.
In Xcode 8/Swift 3 the easiest is to use the unicode escape:
let a = "\u{1F50A}"
It's fun why few people knew this.
You can enter Unicode-symbols directly by holding "Option" and entering hex digit.
All you need: (Sierra example)
goto "Preference -> Keyboards -> Input Sources" and search for "Unicode Hex". It should appears under "Others" section. Next add it and then you be able enter Unicode-char anywhere just selecting this input source.
For example: ✓ = (Alt+2713), € - (20ac), etc.
Most interesting section from 2100 to 2800.
Full list you can found here - Unicode table
P.S.: This method sutable only for four-digit Unicodes
I am going to develop the iPhone app. But I got stuck with one place. I want to write some symbol on the label from the xib file.
The symbols are not on the keyboard but we can get it by the ASCII value.
e.g: the ACSII value for the character sign "mue" is 230 but how to print that symbol "mue" on the label that i dont know.
So please help me for that.
Thanks in advance.
Use whatever editor you like to produce that character, and open your xib in XCode and just copy/paste it in?
Use NSUTF8StringEncoding to encode your string.
For example,
NSString *str = [NSString stringWithUTF8String:"your string for encoding"];
[lblName setText:str];
Following function will also help :
- (NSString *) decodedString:(NSString *) originalString {
NSString *newString = [NSString stringWithUTF8String:[originalString cStringUsingEncoding:[NSString defaultCStringEncoding]]];
return newString;
}
I suggest to use above function.
Pressing Cmd+Ctrl+Space will open a special characters menu. Check if the desired symbol is present. If it isn't, click the gear icon, then select the desired category — add it to the list.
See screenshot below
I think you mean the character 'µ', yes?
If so, you can simply type it into the label by clicking "option" and "m" on your Macintosh keyboard, when you are editing the label in your XIB.
If you can use the unicode number instead, you can do it like this:
NSString *muString = [NSString stringWithFormat:#"%C", 0x03BC];
Write 0x then the unicode number.
Open the "Special Characters"-Panel and search for your character. You can find it at the bottom of the edit menu. There is a shortcut for it too, cmd+opt+t
Copy and paste your character from there to your UILabel.
and btw: option + m = µ
You can simply type into label by using 'Alt' key + 'm' key on key board, when you are editing the label in your XIB and rest of symbols, you can get easily using 'Alt' key and other keys. You can fix 'Alt' key and change other keys(one by one).
I retrieve an NSString from a Property list and display it in a UILabel. The NSString already includes \n s, however the UILabel just displays them as text. How can I tell the UILabel to actually use the \n s as line breaks?
Everything you type into a plist in the plist editor is interpreted as plain text. Try it... put a ' into a field and right click -> view as "plain text" and you'll see it substitutes it for '. Therefore you can't put \n into a plist because it thinks you're just typing text and will treat it as such. Instead of putting \n into your plist use Alt+Enter to get your newline. If you view this as a text file now you'll see \ns printed and new lines acctually shown in the text file.
Now when you output it it won't display \n it will just give it a new line.
Plus, as has been mentioned UITextField is only one line anyway and you probably would benefit from using UITextView.
Well, first, you are going to need a string that you can modify. To accomplish that, you can simply do:
NSMutableString* correctedPath = [path mutableCopy];
At that point, you can use -insertString:atIndex: to insert any characters you need.
You're using the wrong class here.
UITextField doesn't (for all that I know) support multi-line input. For that, you will need a UITextView (it has editing enabled by default). It should interpret \n's without any problems. It also has a lineBreakMode property, if you want to make use of that.
I have a bizarre problem: Somewhere in my HTML/PHP code there's a hidden, invisible character that I can't seem to get rid of. By copying it from Firebug and converting it I identified it as or 'Zero width no-break space'. It shows up as non-empty text node in my website and is causing a serious layout problem.
The problem is, I can't get rid of it. I can't see it in my files even when turning Invisibles on (duh). I can't seem to find it, no search tool seems to pick up on it. I rewrote my code around where it could be, but it seems to be somewhere deeper in one of the framework files.
How can I find characters by charcode across files or something like that? I'm open to different tools, but they have to work on Mac OS X.
You don't get the character in the editor, because you can't find it in text editors. #FEFF or #FFFE are so-called byte-order marks. They are a Microsoft invention to tell in a Unicode file, in which order multi-byte characters are stored.
To get rid of it, tell your editor to save the file either as ANSI/ISO-8859 or as Unicode without BOM. If your editor can't do so, you'll either have to switch editors (sadly) or use some kind of truncation tool like, e.g., a hex editor that allows you to see how the file really looks.
On googling, it seems, that TextWrangler has a "UTF-8, no BOM" mode. Otherwise, if you're comfortable with the terminal, you can use Vim:
:set nobomb
and save the file. Presto!
The characters are always the very first in a text file. Editors with support for the BOM will not, as I mentioned, show it to you at all.
If you are using Textmate and the problem is in a UTF-8 file:
Open the file
File > Re-open with encoding > ISO-8859-1 (Latin1)
You should be able to see and remove the first character in file
File > Save
File > Re-open with encoding > UTF8
File > Save
It works for me every time.
It's a byte-order mark. Under Mac OS X: open terminal window, go to your sources and type:
grep -rn $'\xFEFF' *
It will show you the line numbers and filenames containing BOM.
In Notepad++, there is an option to show all characters. From the top menu:
View -> Show Symbol -> Show All Characters
I'm not a Mac user, but my general advice would be: when all else fails, use a hex editor. Very useful in such cases.
See "Comparison of hex editors" in WikiPedia.
I know it is a little late to answer to this question, but I am adding how to change encoding in Visual Studio, hope it will be helpfull for someone who will be reading this sometime:
Go to File -> Save (your filename) as...
And in File Explorer window, select small arrow next to the Save button -> click Save with Encoding...
Click Yes (on Do you want to replace existing file dialog)
And finally select e.g. Unicode (UTF-8 without signature) - that removes BOM