我有这个字符串
NSString * str = @ "01 00 00 41 8B 00 01 00 00 40 BC 00 01 00 00 43 0D 00";
我尝试使用此功能将其转换为 NSacii
- (NSString *)hexToString:(NSString *)string {
NSMutableString * newString = [[NSMutableString alloc] init];
NSScanner *scanner = [[NSScanner alloc] initWithString:string];
unsigned value;
while([scanner scanHexInt:&value]) {
[newString appendFormat:@"%c",(char)(value & 0xFF)];
}
string = [newString copy];
[newString release];
return [string autorelease];
}
它工作完美,但是当我想将字符串转换为十六进制时我找不到 00 这意味着结果是 01 41 8B 01 40 BC 01 43 0D