• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Converting four char code
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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.
  • Follow-Ups:
    • Re: Converting four char code
      • From: Eric Blairs <email@hidden>
References: 
 >re: Converting four char code (From: Diggory Laycock <email@hidden>)

  • Prev by Date: RE: WSMakeStubs code issues
  • Next by Date: Re: RTFD File Encoding
  • Previous by thread: re: Converting four char code
  • Next by thread: Re: Converting four char code
  • Index(es):
    • Date
    • Thread