Kanji to Pinyin
nsmutablestring *ms = [[Nsmutablestring alloc] initwithstring:@"I am a Chinese"];if(Cfstringtransform (__bridge cfmutablestringref) MS,0, Kcfstringtransformmandarinlatin, NO)) {NSLog (@"pingying:%@", MS);//Wǒshìzhōng Guórén}if(Cfstringtransform (__bridge cfmutablestringref) MS,0, Kcfstringtransformstripdiacritics, NO)) {NSLog (@"pingying:%@", MS);//wo shi Zhong guo ren}
Chinese Pinyin Sequencer
#define Gb18030_encoding cfstringconvertencodingtonsstringencoding (kcfstringencodinggb_18030_2000) + (NSComparator) Compor { return ^nscomparisonresult (nsstring *obj1, NSString *obj2) { *str1 = [obj1 Stringbyaddingpercentescapesusingencoding:gb18030_encoding]; *STR2 = [Obj2 stringbyaddingpercentescapesusingencoding:gb18030_encoding]; return [str1 compare:str2];} ;}
Principle: Chinese GB encoding is to use pinyin sort of hack a bit: In the stringbyaddingpercentescapesusingencoding: back with 16-bit code to convert Chinese to ASCII to compare more concise.
Kanji to pinyin, Chinese pinyin sequencer