Skip to content

Instantly share code, notes, and snippets.

@tsbob
Created July 31, 2012 03:23
Show Gist options
  • Save tsbob/3213239 to your computer and use it in GitHub Desktop.
Save tsbob/3213239 to your computer and use it in GitHub Desktop.
nsstring 2 nsdata
NSString* aStr = [[NSString alloc] initWithData:aData encoding:NSASCIIStringEncoding];
NSData* aData = [aStr dataUsingEncoding: NSASCIIStringEncoding];
//If the data is null-terminated, you should instead use -stringWithUTF8String: to avoid the extra \0 at the end.
NSString* newStr = [NSString stringWithUTF8String:[theData bytes]];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment