开发者

problem in converting NSString to NSData

开发者 https://www.devze.com 2023-03-06 20:39 出处:网络
I want to convert one NSString to NSData. on Using encoding am getting different value in NSData by displaying it using its descripti开发者_C百科on property.

I want to convert one NSString to NSData. on Using encoding am getting different value in NSData by displaying it using its descripti开发者_C百科on 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.


Create a new NSString:

NSString *newString = [[[NSString alloc] initWithData: data encoding: NSUTF8StringEncoding] autorelease];


You can use NSString's initWithData:encoding: method:

NSString *str=@"80369F4";
NSData *data = [str dataUsingEncoding:NSUTF8StringEncoding];
NSString *sameString = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
0

精彩评论

暂无评论...
验证码 换一张
取 消