• 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 string to encoding
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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

  • Follow-Ups:
    • Re: Converting string to encoding
      • From: "dexter morgan" <email@hidden>
References: 
 >Converting string to encoding (From: Dex Morgan <email@hidden>)

  • Prev by Date: Re: Converting string to encoding
  • Next by Date: Re: Converting string to encoding
  • Previous by thread: Re: Converting string to encoding
  • Next by thread: Re: Converting string to encoding
  • Index(es):
    • Date
    • Thread