Possible Duplicate:
Convert UTF-8 encoded NSData to NSString
I need to to convert the NSData read from file to NSString. How to do it?
Possible Duplicate:
Convert UTF-8 encoded NSData to NSString
I need to to convert the NSData read from file to NSString. How to do it?
NSString
provides an initializer for this purpose.
// NSData *data = [NSData data];
NSString *string = [[[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding] autorelease];
You can do it this way
NSString *yourStr= [[[NSString alloc] initWithData:data
encoding:NSUTF8StringEncoding] autorelease];
or the ohther way to use it when the data ends with a null is:-
NSString *yourStr= [NSString stringWithUTF8String:[theData bytes]];
NSString *convertedString = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding]