Re: Converting four char code
Re: Converting four char code
- Subject: Re: Converting four char code
- From: Michael Tsai <email@hidden>
- Date: Tue, 11 Feb 2003 12:18:02 -0500
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?
The way I do it is to put the unsigned long in an NSData and then
convert that to an NSString with NSMacOSRomanStringEncoding.
On Tuesday, February 11, 2003, at 07:10 AM, Diggory Laycock wrote:
If you want the code to become an NSString - the easiest way is the
Foundation Function: NSString *NSFileTypeForHFSTypeCode(OSType
hfsFileTypeCode)
My understanding is that the NSString representation that that function
returns is supposed to be opaque. You can pass it to NSOpenPanel and
the like, but should not look inside it.
_______________________________________________
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.