iOS开发--汉字转成没有声调也没有空格的拼音
//汉字转成没有声调也没有空格的拼音
- (NSString *)transformToPinYin:(NSString *)wordStr {
NSMutableString *mutableString = [NSMutableString stringWithString:wordStr];
//带声调
CFStringTransform((CFMutableStringRef)mutableString, NULL, kCFStringTransformToLatin, false);
//不带声调
CFStringTransform((CFMutableStringRef)mutableString, NULL, kCFStringTransformStripDiacritics, false);
//西安 -> xi an -> xian
return [mutableString stringByReplacingOccurrencesOfString:@" " withString:@""];
}
- (NSString *)transformToPinYin:(NSString *)wordStr {
NSMutableString *mutableString = [NSMutableString stringWithString:wordStr];
//带声调
CFStringTransform((CFMutableStringRef)mutableString, NULL, kCFStringTransformToLatin, false);
//不带声调
CFStringTransform((CFMutableStringRef)mutableString, NULL, kCFStringTransformStripDiacritics, false);
//西安 -> xi an -> xian
return [mutableString stringByReplacingOccurrencesOfString:@" " withString:@""];
}