Re: stringWithFormat / Rendering Text (iOS)
Re: stringWithFormat / Rendering Text (iOS)
- Subject: Re: stringWithFormat / Rendering Text (iOS)
- From: Jens Alfke <email@hidden>
- Date: Thu, 24 May 2012 08:48:05 -0700
On May 24, 2012, at 5:50 AM, Jason Teagle wrote:
> (I've since discovered that the %@ and @"xxx" way works just fine, so I'll stick with that.
Good :) The problem with using "%s" is that it doesn't work well with non-ASCII characters. Cocoa has to assume some character encoding to map the bytes to Unicode, and the rules for what encoding it chooses are both obscure and not very useful. (In short: it depends on the user's language/locale, and the default for English is the obsolete MacRoman encoding, not UTF-8 or even ISO-Latin-1.)
To reiterate: the only time you should use "%s" is if the C string you're passing in is guaranteed to be pure ASCII. Which is not very common.
In other circumstances, use "%@" and convert the C string to an NSString using -[NSString initWithCString:encoding:].
—Jens
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden