Nat! bio photo


Senior Mull.

Twitter RSS


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:.



A photo of Stephane

From: Stephane

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.

A photo of znek

From: znek

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.

A photo of Nat!

From: Nat!

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.

A photo of Stefan Kreutter

From: Stefan Kreutter

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

Post a comment

All comments are held for moderation; basic HTML formatting accepted.

E-mail: (not published)