//获取拼音首字母(传入汉字字符串, 返回大写拼音首字母)
+(NSString *)FirstCharactor:(NSString *)pString
{
//转成了可变字符串
NSMutableString *pStr = [NSMutableString stringWithString:pString];
//先转换为带声调的拼音
CFStringTransform((CFMutableStringRef)pStr,NULL, kCFStringTransformMandarinLatin,NO);
//再转换为不带声调的拼音
CFStringTransform((CFMutableStringRef)pStr,NULL, kCFStringTransformStripDiacritics,NO);
//转化为大写拼音
NSString *pPinYin = [pStr capitalizedString];
//获取并返回首字母
return [pPinYin substringToIndex:1];
}
网友评论