Re: Reading in UTF-8 to Data
Re: Reading in UTF-8 to Data
- Subject: Re: Reading in UTF-8 to Data
- From: Nick Zitzmann <email@hidden>
- Date: Thu, 15 Jul 2010 16:19:18 -0600
On Jul 15, 2010, at 4:03 PM, Brad Stone wrote:
> 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?
Looks like you need to translate the text in the XML file using a MIME quoted-printable decoder, and then run the results through a UTF-8 decoder. Quoted-printable sequences start with a = and the next two characters indicate the hex value of the character. For example, 0xe280a2 is the bullet character (U+2022) in UTF-8. See RFC 2045 for more details.
Nick Zitzmann
<http://www.chronosnet.com/>
_______________________________________________
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