Re: stringWithFormat / Rendering Text (iOS)
Re: stringWithFormat / Rendering Text (iOS)
- Subject: Re: stringWithFormat / Rendering Text (iOS)
- From: Ken Thomases <email@hidden>
- Date: Thu, 24 May 2012 10:52:47 -0500
On May 24, 2012, at 2:49 AM, Jason Teagle wrote:
> First, a quick question about +stringWithFormat: If I want to have a literal string as one of the parameters to the format, which is correct / best:
>
> NSString *textToDraw = [NSString stringWithFormat: @"%s",
> "my string"];
>
> or
>
> NSString *textToDraw = [NSString stringWithFormat: @"%@",
> @"my string"];
Given what's been said elsewhere about these being cut-down example snippets and not anything real... Never use the "%s" format specifier. It interprets the C string argument in a completely unreliable encoding. If the argument contains or could contain any non-ASCII characters, you're likely to get a nasty surprise. Worse, the nasty surprise may not show up until your code is run on a system set to a language/locale other than your usual one.
Regards,
Ken
_______________________________________________
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