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 (Cocoa-dev@lists.apple.com) 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: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com