- (NSString *)transform:(NSString *)chinese {
// 将NSString转化为NSMutableString,如:苹果
NSMutableString *pinyin = [chinese mutableCopy];
// 将汉字转化为拼音,带音调,如:píng guǒ
CFStringTransform((__bridge CFMutableStringRef)pinyin, NULL, kCFStringTransformMandarinLatin, NO);
NSLog(@"带音调的拼音:%@", pinyin);
// 将汉字转化为拼音,不带音调,如:ping guo
CFStringTransform((__bridge CFMutableStringRef)pinyin, NULL, kCFStringTransformStripCombiningMarks, NO);
NSLog(@"不带音调的拼音:%@", pinyin);
// 返回结果
return pinyin;
}
网友评论