03.08.04

Static Unicode in NSString

I wasted quite a bit of time to get some unicode into an NSString. My preferred way would have been @"This is a checkmark: \u2714" but that didn't work. I am too lame to hand code it in UTF8, which I should know but I actually don't. Eventually I used -initWithCharacters:length:.

Boring... Posted by Nat! at 03.08.04 23:27

Comments

Why not:

[NSString stringWithString:NSLocalizedStringFromTable(@"My Unicode String I live and die for",@"My Unicode Table",@"Yes this solution sucks a bit")];

and a My Unicode Table.strings file not localized in fact.

Posted by: Stephane at 04.08.04 11:53

Nat's definitely right, this really is something which belongs into gcc - at least in the year 2004. I've stumbled across this earlier and chose the way Stephane proposes also. IMO there's no other portable way of achieving this.

Posted by: znek at 04.08.04 12:41

I don't like that solution that much because I have now that .strings file just for this problem. My code is in a framework, which I just feel the application will have a problem locating the .strings file at the opportune moment.

Posted by: Nat! at 05.08.04 20:50

What about: [NSString stringWithFormat:@"String with unicode %C", (unichar) 0x2714] ?

Posted by: Stefan Kreutter at 20.01.05 14:21