Reputation: 5773
I want to convert one NSString
to NSData
. on Using encoding am getting different value in NSData
by displaying it using its description property.
I have
NSString *str=@"80369F4";
NSData *data = [str dataUsingEncoding:NSUTF8StringEncoding];
on printing [data description];
am getting some different values...
how to extract the same string from the NSData
.. pl help me out on this problem.
Upvotes: 2
Views: 844
Reputation: 5999
You can use NSString's initWithData:encoding: method:
NSString *str=@"80369F4";
NSData *data = [str dataUsingEncoding:NSUTF8StringEncoding];
NSString *sameString = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
Upvotes: 4
Reputation: 14417
Create a new NSString:
NSString *newString = [[[NSString alloc] initWithData: data encoding: NSUTF8StringEncoding] autorelease];
Upvotes: 7