Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > Unicode string encoding Q - What encoding is this?

Unicode string encoding Q - What encoding is this?
Thread Tools
Professional Poster
Join Date: Oct 2001
Location: London
Status: Offline
Reply With Quote
Sep 7, 2003, 07:24 AM
 
Hi,

I am currently working on an application that extracts info from specific kinds of Binary files (which are encoded LittleEndian).

I have got Ints out of the Data fine - using CFSwapInt32LittleToHost or CFSwapInt16LittleToHost

However I am having problems extracting a String.
I know the offset into the data where the string is, and the length of the string:

Code:
nameData = [symbianFileData subdataWithRange: NSMakeRange( componentNameOffset , componentNameSize) ]; NSLog(@"nameData: %@", nameData);
gives:

Code:
nameData: <4f007000 65007200 6100>
(notice the alternating 00s)

When I try to convert that data into a string however, I get a string separated by spaces:

Code:
componentName = [[NSString alloc] initWithData: nameData encoding: NSNonLossyASCIIStringEncoding ];
gives:

Code:
componentName: O\\000p\\000e\\000r\\000a\\000
I've tried various NSStringEncodings - but they all end up the same (with the Spaces (\\000) between each character.)


Is this something to do with the fact that the original data is Little-Endian?

Do I need to do some kind of byteSwapping on the Data?


Thanks,
Diggory
     
Senior User
Join Date: Nov 2000
Status: Offline
Reply With Quote
Sep 7, 2003, 08:13 AM
 
There's a lot of Unicode questions and answers here: http://www.unicode.org/unicode/faq/utf_bom.html

Note that UTF-8 strings do not need to be byte swapped at all. Ever. Other UTF formats may need it however.

- proton
     
Mac Elite
Join Date: Sep 2000
Location: Tempe, AZ
Status: Offline
Reply With Quote
Sep 7, 2003, 08:24 AM
 
Your string data looks like its Unichar16, not UTF8. Two bytes per character. Try using the method that creates an NSString using a buffer of unichars.
Geekspiff - generating spiffdiddlee software since before you began paying attention.
     
Professional Poster
Join Date: Oct 2001
Location: London
Status: Offline
Reply With Quote
Sep 7, 2003, 09:29 AM
 
Originally posted by smeger:
Your string data looks like its Unichar16, not UTF8. Two bytes per character. Try using the method that creates an NSString using a buffer of unichars.
You Star it worked! Thank-you very much.
     
   
Thread Tools
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Top
Privacy Policy
All times are GMT -5. The time now is 02:22 PM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2