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

[NSString initWithData: encoding:]


  • Subject: [NSString initWithData: encoding:]
  • From: Robin Hermann <email@hidden>
  • Date: Mon, 17 Jan 2005 18:31:46 +0100

As a follow up on NSData and strings

The following works (not using -CString), and it should be the right way according to the Apple docs.

NSData *note = [record objectForKey:@"notes"];
if (note != Nil && [note isKindOfClass:[NSData class]]) {
unsigned long len = [note length];
unsigned char noteBuffer[len];
[note getBytes:noteBuffer];
NSString *noteString = [NSString stringWithUTF8String:noteBuffer];
[notes setString:noteString];
}


Then someone suggested: use [NSString initWithData: encoding:];
Tested the following code, resulting in a crash:
NSData *note = [record objectForKey:@"notes"];
if (note != Nil && [note isKindOfClass:[NSData class]]) {
NSString *noteString;
[noteString initWithData:note encoding:NSISOLatin1StringEncoding];
[notes setString:noteString];
}


ISO Latin1 is the default encoding of MySQL
Now I'm completely lost, what I'm doing wrong here?

Robin Hermann
 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Follow-Ups:
    • Re: [NSString initWithData: encoding:]
      • From: Clark Cox <email@hidden>
  • Prev by Date: long long
  • Next by Date: Re: long long
  • Previous by thread: Re: long long
  • Next by thread: Re: [NSString initWithData: encoding:]
  • Index(es):
    • Date
    • Thread