//汉字转成没有声调也没有空格的拼音
- (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:@""];
}
时间: 2024-10-07 00:01:13