• 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: Working with an Unsupported Character Encoding (ANSEL)
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Working with an Unsupported Character Encoding (ANSEL)


  • Subject: Re: Working with an Unsupported Character Encoding (ANSEL)
  • From: Jens Alfke <email@hidden>
  • Date: Sat, 3 Oct 2009 21:31:50 -0700


On Oct 3, 2009, at 8:11 AM, Thomas Wetmore wrote:

1. Apparently reading a file to an NSString using the NSASCIIStringEncoding returns each of the bytes of the file exactly as they were, that is, the 8-bit bytes seem to be read exactly as they were. So is it true that reading with NSASCIIStringEncoding doesn't mess around with any of the 8-bit bytes in the file?

I'm surprised to hear that. Usually NSString's behavior is that if the data contains a character illegal for that encoding, it causes an error; so in the case of NSASCIIStringEncoding, any bytes >127 would cause it to return nil. Maybe reading a string from a file is an exception, but I wouldn't rely on this.


As Adam said, it's safer to read the file as NSData. Then you can cast its bytes to an array of char, allocate a C array of UniChar and fill it with the translated characters, and pass that array to an NSString initializer.

—Jens_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


References: 
 >Working with an Unsupported Character Encoding (ANSEL) (From: Thomas Wetmore <email@hidden>)

  • Prev by Date: Bundle is not using icon or CFBundleIdentifier
  • Next by Date: Re: Bundle is not using icon or CFBundleIdentifier
  • Previous by thread: Re: Working with an Unsupported Character Encoding (ANSEL)
  • Next by thread: Probs with "BetterAuthorizationSample"-code
  • Index(es):
    • Date
    • Thread