views:

255

answers:

2

Hi,

I have utf8 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.

+2  A: 
NSString* newStr = [[NSString alloc] initWithData:theData
                                         encoding:NSUTF8StringEncoding];

If the data is null-terminated, you should instead use

NSString* newStr = [NSString stringWithUTF8String:[theData bytes]];
KennyTM
+1  A: 

You could call + (id)stringWithUTF8String:(const char *)bytes.

Gouldsc
Kenny just beat me to it.
Gouldsc