Can anyone tell me how to convert an unsigned char to an NSString?
Here's the code I am using, but for some reason if I try to do anything with the NSString, like set a UITextView text, it gives me an error. The NSLog works correctly though. Thanks in advance.
- (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];
}
If tag
is a C string (null-terminated, that is), then you can use [NSString stringWithUTF8String:(char *)tag]
. If you want the hex values, then your code using %02x
is fine.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With