Re: Converting string to encoding
Re: Converting string to encoding
- Subject: Re: Converting string to encoding
- From: Jens Alfke <email@hidden>
- Date: Sat, 14 Jun 2008 08:36:33 -0700
I think the problem is here:
[newString appendFormat:@"%c", (char)character];
This interprets the character as Unicode, since NSString is pure
Unicode. Then when you ask for the data in ISO-Latin-1, that character
gets encoded from Unicode to ISO-Latin-1, which changes its numeric
value (if it's > 7F). But then you read it back into a string as ISO-
Latin-1, which will keep the changed value, so it's not the character
you intended.
I don't think it's best to do this by translating back and forth
between data and string. It's slow, and there's too much opportunity
for encoding mistakes like this one. Instead, just leave it as NSData
and scan through the raw bytes; then convert the unquoted result data
directly into the desired string encoding.
—Jens
Attachment:
smime.p7s
Description: S/MIME cryptographic signature
_______________________________________________
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