Re: Converting four char code
Re: Converting four char code
- Subject: Re: Converting four char code
- From: Eric Blairs <email@hidden>
- Date: Tue, 11 Feb 2003 13:08:03 -0500
On 2/11/03 at 12:18 PM, Michael Tsai <email@hidden> wrote:
>
On Monday, February 10, 2003, at 11:21 PM, Eric Blairs wrote:
>
>
>I've seen a number of these floating around, but the one I got in
>
>some of my code is from Andrew Stone's Cocoa Files:
>
>
>
> - (NSString *)stringFromCode:(unsigned long)code {
>
> unsigned char c[5];
>
>
>
> c[0] = code >> 24;
>
> c[1] = (code >> 16) & 0xff;
>
> c[2] = (code >> 8) & 0xff;
>
> c[3] = code & 0xff;
>
> c[4] = '\0'; // don't forget to terminate the cstring!
>
>
>
> return [NSString stringWithCString:c];
>
> }
>
>
Does this work reliably on systems with different default encodings?
>
I haven't gotten to the point of testing with different encoding types. Since my
personal stuff seems to be in a state of constant development instead of hitting
a feature freeze point, I've only been doing basic testing.
>
The way I do it is to put the unsigned long in an NSData and then
>
convert that to an NSString with NSMacOSRomanStringEncoding.
That's something I could do as well :)
--Eric
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.