开发者

problem in converting NSString to NSData

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜