IOS: converting Chinese characters to PinYin (class method) and ios pinyin
I wrote an article about changing Chinese characters to PinYin before, and then I used it myself, and it was a little troublesome.
Here, I directly write a class Method
Click to download source code
This is a class, and only one class method can be used for direct import, but I declare the output result first, in uppercase, and there are spaces in the pinyin format between Chinese characters and Chinese characters.
That is:
Haha = HA
Length:
2 5
Nothing else.
Here I also stick the source code method. Let's watch it.
+ (NSString *) stringByChinaese :( NSString *) string {if (string. length <= 0) {return nil;} NSMutableString * source = [string mutableCopy]; CFStringTransform (_ bridge CFMutableStringRef) source, NULL, kCFStringTransformMandarinLatin, NO ); CFStringTransform (_ bridge CFMutableStringRef) source, NULL, kCFStringTransformStripDiacritics, NO); return [source uppercaseString];}