我需要将字符串编码为其他格式。有人知道这是哪种编码吗?以及如何使用objective-c获得结果?
更新时间 2013-10-22 02:23:49
我不确定这是否是最好的方法。它解决了我的问题。
NSString *result_string = @"";
for (int i = 0; i < string.length; i++) {
int a = [string characterAtIndex:i];
unsigned long long int theNumber = a;
NSString *ascii_string = [NSString stringWithFormat:@"%llX", theNumber];
//61 -> 6100, 4E03 -> 034E
if (ascii_string.length == 2) {
result_string = [NSString stringWithFormat:@"%@%@00", result_string, ascii_string];
} else if (ascii_string.length == 4) {
NSString *first2 = [ascii_string substringToIndex:2];
NSString *last2 = [ascii_string substringFromIndex:2];
result_string = [NSString stringWithFormat:@"%@%@%@", result_string, last2, first2];
} else {
NSLog(@"length unknown: %d", ascii_string.length);
}
}
return result_string;