Re: lengthOfBytesUsingEncoding not correct
Re: lengthOfBytesUsingEncoding not correct
- Subject: Re: lengthOfBytesUsingEncoding not correct
- From: Markus Spoettl <email@hidden>
- Date: Fri, 15 Feb 2013 09:25:29 +0100
On 2/15/13 9:13 AM, Gerriet M. Denkmann wrote:
This program:
NSString *s = @"หัวหิน";
NSUInteger l3 = [ s lengthOfBytesUsingEncoding: NSUTF16StringEncoding ];
NSLog(@"%s NSUTF16StringEncoding length %lu", __FUNCTION__, l3);
NSData *d9 = [ s dataUsingEncoding: NSUTF16StringEncoding ];
NSLog(@"%s NSUTF16StringEncoding data %lu %@", __FUNCTION__, [d9 length], d9);
prints:
NSUTF16StringEncoding length 12
NSUTF16StringEncoding data 14 <fffe2b0e 310e270e 2b0e340e 190e>
Why is the number of bytes first 12, then 14?
(NSUTF16StringEncoding data has 2 leading byte order bytes - but why does lengthOfBytesUsingEncoding not take this into it's count?)
The data includes the Byte Order Mark (BOM) 0xfffe (see
http://en.wikipedia.org/wiki/Byte_order_mark).
Documentation on -dataUsingEncoding:allowLossyConversion: explains that it is
doing that.
Regards
Markus
--
__________________________________________
Markus Spoettl
_______________________________________________
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