Re: Initializing a string with an NSData
Re: Initializing a string with an NSData
- Subject: Re: Initializing a string with an NSData
- From: Peter Ammon <email@hidden>
- Date: Mon, 02 Jul 2001 09:49:48 -0700
on 6/29/01 5:54 PM, Aki Inoue at email@hidden wrote:
>
>
On Friday, 6 29, 2001, at 04:53 PM, Peter Ammon wrote:
>
>
>
> A super easy way to create an NSString from ASCII data stored in an
>
> NSData
>
> is
>
>
>
> NSString* myString=[NSString stringWithCString:[myData bytes]
>
> length:[myData
>
> length]];
>
>
>
> -Peter
>
Peter,
>
>
Unless you're absolutely sure that your software is never used by
>
non-English users, it is extremely dangerous to assume default C string
>
encoding is ASCII. For example, the code might lead to mysterious
>
crasher problems when executed in Japanese localization.
>
>
Aki
Interesting; I hadn't thought of this. In my case, the data I'm using to
create a string is sent from a server as ASCII, so I'm forced to interpret
it as ASCII, at least initially. Will localization affect how the
stringWithCString: method operates?
-Peter