• 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 vs. unicode encoding
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSString vs. unicode encoding


  • Subject: Re: NSString vs. unicode encoding
  • From: Jens Alfke <email@hidden>
  • Date: Tue, 15 Sep 2009 21:50:40 -0700


On Sep 15, 2009, at 9:04 PM, Johan Kool wrote:

NSString *stringA = @"hello\040world";
NSString *stringB = [NSString stringWithUTF8String:"hello \040world"] ;

I'm confused. '\040' is a regular ascii space character (040 = 32 decimal). What's unusual about either of these strings?


// This does not work (as expected)
NSLog([NSString stringWithUTF8String:[stringA UTF8String]]);

I would expect that to work (i.e. output "hello world".) What is the actual output?


// Nor does this work
NSLog([NSString stringWithUTF8String:[[stringA dataUsingEncoding:NSUTF8StringEncoding] bytes]]);

That is liable to misbehave or crash, since stringWithUTF8String: expects a null-terminated string, but -bytes doesn't produce null- terminated data.


—Jens_______________________________________________

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


  • Follow-Ups:
    • Re: NSString vs. unicode encoding
      • From: Johan Kool <email@hidden>
References: 
 >NSString vs. unicode encoding (From: Johan Kool <email@hidden>)

  • Prev by Date: Re: Filtering a table view using NSSearchField
  • Next by Date: Re: [myNSWindow setDocumentEdited:dirtyB] fail ??
  • Previous by thread: NSString vs. unicode encoding
  • Next by thread: Re: NSString vs. unicode encoding
  • Index(es):
    • Date
    • Thread