黑马程序员技术交流社区
标题:
ios将汉子字符串转化为拼音
[打印本页]
作者:
Abbiamo
时间:
2016-9-1 21:14
标题:
ios将汉子字符串转化为拼音
- (NSString *)chineseToPinyin:(NSString *)chinese withSpace:(BOOL)withSpace {
CFStringRef hanzi = (__bridge CFStringRef)chinese;
CFMutableStringRef string = CFStringCreateMutableCopy(NULL, 0, hanzi);
CFStringTransform(string, NULL, kCFStringTransformMandarinLatin, NO);
CFStringTransform(string, NULL, kCFStringTransformStripDiacritics, NO);
NSString *pinyin = (NSString *)CFBridgingRelease(string);
if (!withSpace) {
pinyin = [pinyin stringByReplacingOccurrencesOfString:@" " withString:@""];
}
return pinyin;
}
欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/)
黑马程序员IT技术论坛 X3.2