Re: NSString really Unicode?
Re: NSString really Unicode?
- Subject: Re: NSString really Unicode?
- From: Shawn Erickson <email@hidden>
- Date: Fri, 12 Mar 2004 07:53:47 -0800
On Mar 12, 2004, at 7:16 AM, James J. Merkel wrote:
Here are the applicable lines of code:
fread(valueBuf, sizeof(char), valueLength, ifp);
valueString = [[NSString alloc]initWithBytes:valueBuf
length:valueLength encoding:kCFStringEncodingASCII];
NSLog(@"the value string = %d\n", [valueString intValue]);
For the encoding, I have tried various string encodings in core
foundation.
A dump from HexEdit of the applicable part of the file being read is:
31 00 30 00 36 00 34 00 35 00 30 00 37 00 33 00
39 00 35 00 00 00
This is a Unix time(c) style format string - seconds since 1/01/1970
- encoded in Unicode.
The NSLog above just prints out 1 -- the first digit of the string.
Looking at the data it is an ASCII character followed by a null (zero).
So the C string is terminated after the first character if you attempt
to read it in with ASCII encoding which is a 1 byte per character
encoding.
Why are you using kCFStringEncoding... flags instead of the NS based
flags for encoding.
Did you try NSUnicodeStringEncoding?
Anyway this looks like a byte flipped encoding without a BOM it may
have a problem reading it as a result... what is the source of this
file? What exact encoding was used to create it?
-Shawn
_______________________________________________
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.