• 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
Reading in UTF-8 to Data
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Reading in UTF-8 to Data


  • Subject: Reading in UTF-8 to Data
  • From: Brad Stone <email@hidden>
  • Date: Thu, 15 Jul 2010 18:03:12 -0400

I'm having trouble getting text to appear properly in an NSTextView which is binded to an NSData attribute in core data.  I've been all over the internet but I'm still stumped.

The original text looks like this:
There is a period at the end of this sentence.
You should have also just seen a line return and here • is a option-8 bullet character.

This text is saved in an XML file that starts with <?xml version="1.0" encoding="UTF-8"?>

My goal is to write code to read this XML file and create an NSData object for the text.  This is what I've written:
NSString *s = [childNode stringValue];  //assume this child is the correct text
NSData *noteData = [s dataUsingEncoding:NSUnicodeStringEncoding allowLossyConversion:YES];  // I also tried NSUTF8StringEncoding

This results in the following appearing in my NSTextView
There is a period at the end of this sentence=2E=0DYou should have also jus= t seen a line return and here =E2=80=A2 is a option-8 bullet character= =2E


I'd like to do the correct encoding but there's something wrong and I don't want to resort to the find and replace method. (i.e. find =2E and replace with ".")

The actual text in the XML file is:
<Note>There is a period at the end of this sentence=2E=0DYou should have also jus=
t seen a line return and here =E2=80=A2 is a option-8 bullet character=
=2E</Note>

(why there's an = between the "s" and "t" in the word "just" is confusing).

Can anyone help?

Thank you

_______________________________________________

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: Reading in UTF-8 to Data
      • From: Nick Zitzmann <email@hidden>
  • Prev by Date: Re: Live updating user defaults from a prefpane to a running app
  • Next by Date: Re: Adding an image to a project
  • Previous by thread: Re: non-pointer instance variable
  • Next by thread: Re: Reading in UTF-8 to Data
  • Index(es):
    • Date
    • Thread