I have a NSString with hex string like "68656C6C6F" which means "hello".
Now I want to convert the hex string into another NSString object which shows "hello". How to do that ?
See Question&Answers more detail:osI have a NSString with hex string like "68656C6C6F" which means "hello".
Now I want to convert the hex string into another NSString object which shows "hello". How to do that ?
See Question&Answers more detail:osI am sure there are far better, cleverer ways to do this, but this solution does actually work.
NSString * str = @"68656C6C6F";
NSMutableString * newString = [[[NSMutableString alloc] init] autorelease];
int i = 0;
while (i < [str length])
{
NSString * hexChar = [str substringWithRange: NSMakeRange(i, 2)];
int value = 0;
sscanf([hexChar cStringUsingEncoding:NSASCIIStringEncoding], "%x", &value);
[newString appendFormat:@"%c", (char)value];
i+=2;
}