我在这里遇到了一些奇怪的问题。代码如下

NSMutableString *unicodeString = [NSMutableString string];
for (NSUInteger i = 0; i < [data length]; i++) {
    unsigned char byte;
    [data getBytes:&byte range:NSMakeRange(i, 1)];
    unichar unicodeChar = byte;
    NSString *appendString = [NSString stringWithFormat:@"%C",[_toUnicode unicharFromCIDString:unicodeChar]];
    [unicodeString appendFormat:@"%@",appendString];
    NSLog(@"%@",appendString); //1
}
NSLog(@"%@",unicodeString)//2

appendString 打印,但 unicodeString 从不打印。这是因为字节问题吗?我试过保留 appendString 但它仍然无法打印

*更新找到答案

最佳答案

其他方式 :

NSString *appendString = [NSString stringWithCharacters:&unicodeChar length:1];
[unicodeString appendFormat:@"%@", appendString];

关于iphone - 用 unichar 附加字符串,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/7806189/

10-12 20:54