ohho ohho - 1 year ago 59
Objective-C Question

Chinese char* conversion to NSString on iOS?

I'd like to convert GB encoded

char *
to
NSString *
:

char *str = ...
size_t len = ...

NSString *s = [[NSString alloc] initWithBytes:str length:len encoding:???];


encoding:NSUTF8StringEncoding
is available. I wonder it there an predefined encoding for GB Chinese characters? similar to kCFStringEncodingGB_2312_80, defined in
CFStringEncoding
.

Answer Source

You can use the CF string encodings with NSString; from Apple's docs:

Additional encodings are defined in String Programming Guide for Core Foundation (see CFStringEncodingExt.h); these encodings can be used with NSString by first passing the Core Foundation encoding to the CFStringConvertEncodingToNSStringEncoding function.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download