如何在iOS中将unsigned char转换为NSString

dre*_*bot 13 iphone ios4

谁能告诉我如何将unsigned char转换为NSString?

这是我正在使用的代码,但出于某种原因,如果我尝试对NSString做任何事情,比如设置UITextView文本,它会给我一个错误.尽管NSLog工作正常.提前致谢.

- (void)onTagReceived:(unsigned char *)tag
{

NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
NSString *myTag = [NSString stringWithFormat:@"%02x%02x%02x%02x%02x\n",tag[0],tag[1],tag[2],tag[3],tag[4]];

NSLog(@"currentTag: %@",myTag);

[displayTxt setText:myTag];

[pool release];

}
Run Code Online (Sandbox Code Playgroud)

jtb*_*des 22

如果tag是C字符串(以null结尾,那么),那么您可以使用[NSString stringWithUTF8String:(char *)tag].如果你想要十六进制值,那么使用你的代码%02x很好.