Re: UNICODE from a WinTel box
Re: UNICODE from a WinTel box
- Subject: Re: UNICODE from a WinTel box
- From: Finlay Dobbie <email@hidden>
- Date: Wed, 4 Jan 2006 13:47:21 +0000
On 04/01/06, Kenny Millar <email@hidden> wrote:
> My problem is this...
> One of the responses the server sends me contains a long UNICODE string.
>
> The problem is that on Windows the string is stored in the opposite endian
> format from Mac OS.
...
> So when I tried using [NSString stringWithCharacters:(unichar *)&data
> length:sizeof(data)] obviously the resulting string was garbled due to the
> inccorect endian-ness.
Well, the first issue is that length is the number of unichars, not
the size in bytes.
> Is there a neat way to translate the endian-ness of a unicode string, or am
> I going to have to manually swap all the bytes myself?
Since you already know what endian the data you're receiving is, you
can probably assume it'll always be little-endian? On Tiger you can
use kCFStringEncodingUTF16LE to create a CFString, and CFString is
toll-free bridged with NSString.
-- Finlay
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden