iOS 中文转拼音

- (NSString * ) chineseToPinyin:(NSString *) chinese{
CFStringRef hanzi = (__bridge CFStringRef)(chinese);
CFMutableStringRef string = CFStringCreateMutableCopy(NULL, , hanzi); // Boolean CFStringTransform(CFMutableStringRef string, CFRange *range, CFStringRef transform, Boolean reverse);
//string 为要转换的字符串
// range 要转换的范围,NULL 则为全部
//transform 要进行怎么样的转换 //kCFStringTransformMandarinLatin 将汉字转拼音
//reverse 是否支持逆向转换
CFStringTransform(string, NULL, kCFStringTransformMandarinLatin, NO); //kCFStringTransformStripDiacritics去掉声调
CFStringTransform(string, NULL, kCFStringTransformStripDiacritics, NO); NSString * pinyin = (NSString *) CFBridgingRelease(string);
//将中间分隔符号去掉
pinyin = [pinyin stringByReplacingOccurrencesOfString:@" " withString: @""]; return pinyin; }
上一篇:每隔一秒自动执行函数(JavaScript)


下一篇:nodejs通过mocha处理运行文件路径下所有js文件