Re: How to code a NSString literal with UTF8?
Re: How to code a NSString literal with UTF8?
- Subject: Re: How to code a NSString literal with UTF8?
- From: Ali Ozer <email@hidden>
- Date: Wed, 30 Mar 2005 08:59:34 -0800
One possible misconception people come away in these discussions is
that you need to use NSLocalizedString() if you want NSStrings with
non-ASCII characters.
NSLocalizedString and friends are absolutely great choice if you need
localizable strings, that is, strings which will need to be
translated to different languages. The string is read from
a .strings file, which can be made per-language.
However, if all you want is an NSString with some non-ASCII chars in
it, and it's not meant to be shown to the user (and hence doesn't
need to be localized), then it's perfectly fine to create the string
programmatically. One possibility here is:
NSString *s = [NSString stringWithFormat:@"Long %C dash", 0x2014];
You can also do (since \xe2\x80\x94 is the 3-byte UTF-8 string for
0x2014):
NSString *s = [NSString stringWithUTF8String:"Long \xe2\x80\x94
dash"];
but one thing that is not very safe is to include actual high-bit
characters in your source code:
NSString *s = [NSString stringWithUTF8String:"Long — dash"]; //
Not safe; you're at the mercy of any tools you use
and the following is not allowed:
NSString *s = @"Long — dash"; // Not allowed
Ali
Begin forwarded message:
From: Satoshi Matsumoto <email@hidden>
Date: March 29, 2005 20:06:23 PST
To: David Hoerl <email@hidden>, Cocoa-Dev <cocoa-
email@hidden>
Subject: Re: How to code a NSString literal with UTF8?
In such cases, I will code like this...
NSString *foo = NSLocalizedString( @"blah blah", @"some comment" );
And then define the actual Unicode characters in the file
"Localizable.strings."
Satoshi
on 05.3.30 0:17 PM, David Hoerl at email@hidden wrote:
The Xcode editor lets you define a file encoding as UTF8. You can
then type in a line like:
NSString *foo = @"blah blah";
where blah blah have Unicode characters in them with encoded as UTF8.
But, when I ask this string for its characters I get garbage back,
and length is not correct.
What would the best way to do this be?
david
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden