//获取拼音首字母
- (NSString *)firstCharactor:(NSString *)aString
{
//转成了可变字符串
NSMutableString *str = [NSMutableString stringWithString:aString];
//先转换为带声调的拼音
CFStringTransform((CFMutableStringRef)str,NULL, kCFStringTransformMandarinLatin,NO);
NSLog(@"%@", str);
//再转换为不带声调的拼音
CFStringTransform((CFMutableStringRef)str,NULL, kCFStringTransformStripDiacritics,NO);
NSLog(@"%@", str);
//先传化为拼音
NSString *pinYin = [str capitalizedString];
//获取首字母
return [pinYin substringToIndex:1];
}
时间: 2024-10-10 15:55:32