How convert data encoded in GBK/GB2312 to string?

// The builtin encoding does not support GBK/GB2312
String(data: data, encoding: .GBK)

How do I convert data which is encoded in GBK/GB2312 (or anything else) to a string instance?

Answered by imneo in 772043022

After some digging on the net, I myself found a solution:

NSStringEncoding gbkEncoding = CFStringConvertEncodingToNSStringEncoding(kCFStringEncodingGB_18030_2000);
NSString* newStr = [[NSString alloc] initWithData:data encoding:gbkEncoding];
Accepted Answer

After some digging on the net, I myself found a solution:

NSStringEncoding gbkEncoding = CFStringConvertEncodingToNSStringEncoding(kCFStringEncodingGB_18030_2000);
NSString* newStr = [[NSString alloc] initWithData:data encoding:gbkEncoding];
How convert data encoded in GBK/GB2312 to string?
 
 
Q