DGB
DGB

Reputation: 253

How to Get Unicode Value into a String Objective C

I am looking to get the actually unicode value of a character, and put it into an escaped string. I set the title of an NSButton to ± , now I am trying to get the title of this button and convert it back to this "\U00B1";

For Example

unichar theChar = [theButton.title characterAtIndex:0];
//now how would I change the above unichar to an string like @"\\u03b2"

Upvotes: 0

Views: 566

Answers (1)

rmaddy
rmaddy

Reputation: 318814

One solution would be:

unichar theChar = ... 
NSString *escapeCode = [NSString stringWithFormat:@"\\\\u%04x", theChar];

Note how you need four backslashes to get two in the resulting string.

Upvotes: 2

Related Questions