• 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
Get confused with initWithData:encoding:
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Get confused with initWithData:encoding:


  • Subject: Get confused with initWithData:encoding:
  • From: Pierre Molinaro <email@hidden>
  • Date: Tue, 2 Sep 2008 22:25:24 +0200

Hello,

I do not understand what I am doing wrong ; running the following snippet:

NSMutableData * d = [NSMutableData dataWithCapacity:10] ;
const unsigned char data = 0xC0 ; // U+00CO is À
[d appendBytes:& data length:1] ;
NSLog (@"d: %@", d) ;
NSString * source = [[NSString alloc] initWithData:d encoding:NSASCIIStringEncoding] ;
NSLog (@"source: [%@]", source) ;
const BOOL canBeConverted = [source canBeConvertedToEncoding:NSASCIIStringEncoding] ;
NSLog (@"canBeConverted: '%@'", canBeConverted ? @"YES" : @"NO") ;


prints in the Debugger Console:

	d: <c0>
	source: [À]
	canBeConverted: 'NO'

I do not understand why initWithData:encoding succeeds, as 0xC0 is not a valid ASCII character.

The Cocoa doc says about NSASCIIStringEncoding: "Strict 7-bit ASCII encoding within 8-bit chars; ASCII values 0…127 only”.

Then when I send canBeConvertedToEncoding: message to the string with NSASCIIStringEncoding argument, the returned value is NO (correct !)

Could someone tell me why  initWithData:encoding succeeds?

Thanks a lot.

Pierre

_______________________________________________

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: Get confused with initWithData:encoding:
      • From: "Kyle Sluder" <email@hidden>
  • Prev by Date: Detecting File Existence over FTP
  • Next by Date: Declaring multidimensional arrays in obj-c
  • Previous by thread: Re: Detecting File Existence over FTP
  • Next by thread: Re: Get confused with initWithData:encoding:
  • Index(es):
    • Date
    • Thread