Re: NSString really Unicode?
Re: NSString really Unicode?
- Subject: Re: NSString really Unicode?
- From: "James J. Merkel" <email@hidden>
- Date: Fri, 12 Mar 2004 08:47:24 -0800
I was using core foundation string encoding because there was a note in
the NSString documentation that said the NSString encodings were only a
subset of the encodings available (or something to that effect). But I
see that the core foundation encodings aren't compatible with the
NSString encodings. However, I tried various NSString encodings and I
get similar results. Specifically, I tried NSUnicodeStringEncoding,
but this produces Chinese characters (or Japanese, I'm not sure which).
This is a digital camera raw image file. I'm reading metadata in the
file. There is no BOM for the file, and the strings aren't marked with
a BOM, however the file is basically little endian format.
This brings up another question -- what I'm really looking at are
key-value pairs in the file. What I would like to to is use the key to
look up a string in a Localizable.strings file. However, I notice that
if I use UTF-16 encoding for the Localizable.strings file, the strings
are big endian format. Is there a way of making this file little endian
format?
Thanks for the help.
Jim Merkel
On Mar 12, 2004, at 7:53 AM, Shawn Erickson wrote:
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.