Re: NSString really Unicode?
Re: NSString really Unicode?
- Subject: Re: NSString really Unicode?
- From: "James J. Merkel" <email@hidden>
- Date: Fri, 12 Mar 2004 07:16:53 -0800
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.
Jim Merkel
On Mar 11, 2004, at 10:20 PM, Allan Odgaard wrote:
On 12. Mar 2004, at 4:45, James J. Merkel wrote:
Except, which encoding should be used? I have tried several, and
intvalue doesn't seem to work with any of them.
int main (int argc, char const* argv[])
{
[NSAutoreleasePool new];
char data[] = { 0, '1', 0, '2', 0, '3' };
printf("%d\n", [[NSString stringWithCharacters:(unichar*)data
length:3] intValue]);
return 0;
}
This program prints "123", so the method works -- show us your code,
and we might be able to help you out.
Please also include the first few lines of the data file as a hexdump,
e.g. from a terminal write: "hexdump -C <file> | head -5"
_______________________________________________
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.