• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: NSString really Unicode?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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.


  • Follow-Ups:
    • Re: NSString really Unicode?
      • From: "James J. Merkel" <email@hidden>
References: 
 >NSString really Unicode? (From: "James J. Merkel" <email@hidden>)
 >Re: NSString really Unicode? (From: "M. Uli Kusterer" <email@hidden>)
 >Re: NSString really Unicode? (From: "James J. Merkel" <email@hidden>)
 >Re: NSString really Unicode? (From: Allan Odgaard <email@hidden>)
 >Re: NSString really Unicode? (From: "James J. Merkel" <email@hidden>)

  • Prev by Date: Re: NSString really Unicode?
  • Next by Date: [ANN] PlistEdit Pro 1.0.1
  • Previous by thread: Re: NSString really Unicode?
  • Next by thread: Re: NSString really Unicode?
  • Index(es):
    • Date
    • Thread