Re: Initializing a string with an NSData
Re: Initializing a string with an NSData
- Subject: Re: Initializing a string with an NSData
- From: Aki Inoue <email@hidden>
- Date: Tue, 3 Jul 2001 10:23:31 -0700
So is the right thing to do to use initWithData:myData
encoding:NSASCIIStringEncoding when the data is explicitly in ASCII
regardless of the user's localization preference?
Yes.
Or, you could use CFStringCreateWithCString in CF.
Aki
On 2001.07.03, at 09:46, Peter Ammon wrote:
on 7/2/01 2:59 PM, Aki Inoue at email@hidden wrote:
Peter,
Will localization affect how the stringWithCString: method operates?
-stringWithCString:, initWithCString:, & cString methods all assume C
strings are encoded in the default C string encoding.
You can query the encoding using +[NSString defaultCStringEncoding].
Now, the default C string encoding is set up depending on the user's
localization preference.
If the first entry in the user's localization preference is English,
French, German, etc, it's MacRoman encoding.
If it's Japanese, MacJapanese. If Arabic, MacArabic, and so on.
So, it's possible to get unexpected result from these methods depending
on the user's setting if you just assume it to be ASCII.
For example, in MacJapanese, the backslash char (ASCII 0x5C) is mapped
to Unicode 0xA5.
The following line gives you NSString containing an Unicode character
Yen sign (0xA5) in Japanese localization.
string = [NSString stringWithCString:"\"];
With multibyte languages like Japanese, Korean, Chinese, it could be
more fatal if the C string happen to contain a high ASCII character.
In
these cases, the method could fail to convert from C string to Unicode,
and just return nil.
Aki
So is the right thing to do to use initWithData:myData
encoding:NSASCIIStringEncoding when the data is explicitly in ASCII
regardless of the user's localization preference?
-Peter
_______________________________________________
cocoa-dev mailing list
email@hidden
http://www.lists.apple.com/mailman/listinfo/cocoa-dev