IOS Chinese character to PinYin
Here I reference third-party stuff (email: summer2014mht@sina.com ):
Here I use two methods (method 2 is simple and convenient ):
-(NSString *) pinYin
{
// Method 1
// First convert to PinYin with tones
NSMutableString * str = [self mutableCopy];
CFStringTransform (CFMutableStringRef) str, NULL, kCFStringTransformMandarinLatin, NO );
// Convert to PinYin without tone
CFStringTransform (CFMutableStringRef) str, NULL, kCFStringTransformStripDiacritics, NO );
Return str;
// Method 2 (simple and easy to use, and a line of code is convenient for others)
// Return [ChineseToPinyin pinyinFromChiniseString: self];
}
// Supplement:
// Obtain the first letter of the pinyin alphabet
-(NSString *) firstCharactor
{
// 1. First pass to PinYin
NSString * pinYin = [self. pinYinuppercaseString];
// 2. Get the first letter
Return [pinYin substringToIndex: 1];
}