Re: do i have to convert each unichar on ppc and intel
Re: do i have to convert each unichar on ppc and intel
- Subject: Re: do i have to convert each unichar on ppc and intel
- From: Jean-Daniel Dupas <email@hidden>
- Date: Wed, 30 Apr 2008 17:58:38 +0200
Le 30 avr. 08 à 17:24, Nick Rogers a écrit :
hi,
I'm using:
[NSString stringWithCharacters:gptEntry.partName length:36];
where gptEntry struct have been filled in from the disk.
The string shows correct on ppc, while shows garbage on intel.
So how can I convert an entire such unichar array to correct-endian
format?
Is there any built-in support?
Thanks,
Nick
Note this quote from the documentation:
“When creating an NSString object from a UTF-16-encoded string (or a
byte stream interpreted as UTF-16), if the byte order is not otherwise
specified, NSStringassumes that the UTF-16 characters are big-endian,
unless there is a BOM (byte-order mark), in which case the BOM
dictates the byte order. When creating anNSString object from an array
of Unicode characters, the returned string is always native-endian,
since the array always contains Unicode characters in native byte
order.”
If you create your string from the disk, you may use the function
+stringWithContentsOfFile:usedEncoding:error:
or
-initWithContentsOfFile:usedEncoding:error:
And if you want to create your string from a character array (and not
from a file), I think you can use the -initWithBytes:length:encoding:
method passing NSUnicodeStringEncoding as parameter. It may try to use
the BOM in this case, as the encoding parameter do not specified it.
_______________________________________________
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