Created
July 31, 2012 03:23
-
-
Save tsbob/3213239 to your computer and use it in GitHub Desktop.
nsstring 2 nsdata
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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