Re: NSString really Unicode?
Re: NSString really Unicode?
- Subject: Re: NSString really Unicode?
- From: Allan Odgaard <email@hidden>
- Date: Fri, 12 Mar 2004 16:38:19 +0100
On 12. Mar 2004, at 16:16, James J. Merkel wrote:
valueString = [[NSString alloc]initWithBytes:valueBuf
length:valueLength encoding:kCFStringEncodingASCII];
You should use the NS-constants (defined in NSString), since these are
*not* binary compatible with the CF-versions.
// CFString.h
kCFStringEncodingASCII = 0x0600,
// NSString.h
NSASCIIStringEncoding = 1,
31 00 30 00 36 00 34 00 35 00 30 00 37 00 33 00
39 00 35 00 00 00
Ahh, this is UTF-16 alright, but it is in little endian format!
So after reading the data, but before creating the string, try to
insert this code:
uint16_t* tmp = (uint16_t*)valueBuf;
for(size_t i = 0; i < valueLength/2; i++)
CFSwapInt16(*tmp++);
And then use NSUnicodeStringEncoding as the encoding.
The NSLog above just prints out 1 -- the first digit of the string.
Yes, the system (when you give ascii encoding) sees the string as {
'1', '\0', ... }, thus it will be terminated prematurely.
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.