Add string with unichar

I have some kind of weird problem. Code below

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 

print appendString, but unicodeString never prints. Is it due to problems with bytes? I tried to save appendString, but it still won’t print

* UPDATED found the answer

+4
source share
2 answers

I found that the% C problem is for 16-bit unichar, so if I want to add to NSString, I have to use% c, which is 8 bits. It works great.

 NSString *appendString = [NSString stringWithFormat:@"%c",[_toUnicode unicharFromCIDString:unicodeChar]]; [unicodeString appendFormat:@"%@",appendString]; 
+2
source

Another way:

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

All Articles