我有一个cstring,我能够像这样转换成NSUTF8 NSString
NSString *resultString = [[NSString alloc] initWithUTF8String:cstring];
但是我想知道是否有办法将其转换为UTF16String?
答案 0 :(得分:2)
您只需使用NSString' stringWithCString:encoding
NSString *resultString = [NSString stringWithCString:cstring encoding:NSUTF16StringEncoding];
或者,如果您希望坚持使用alloc / init格式:
NSString *resultString = [[NSString alloc] initWithCString:cstring encoding:NSUTF16StringEncoding];