Ccna final exam - java, php, javascript, ios, cshap all in one. This is a collaboratively edited question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.
Monday, June 11, 2012
Convert UTF-8 encoded NSData to NSString
I have UTF-8 encoded nsdata from windows server. I want to convert it to nsstring for iphone. Since data contains characters(like degree symbol) which have different values on both platforms, how do I convert data to string.
NSString* newStr = [[[NSString alloc] initWithData:theData
ReplyDeleteencoding:NSUTF8StringEncoding] autorelease];
If the data is null-terminated, you should instead use
NSString* newStr = [NSString stringWithUTF8String:[theData bytes]];
You could call + (id)stringWithUTF8String:(const char *)bytes.
ReplyDelete