iOS获取字符串(或汉字)首字母

//获取某个字符串或者汉字的首字母.

- (NSString *)firstCharactorWithString:(NSString *)string

{

    NSMutableString *str = [NSMutableString stringWithString:string];

    CFStringTransform((CFMutableStringRef) str, NULL, kCFStringTransformMandarinLatin, NO);

    CFStringTransform((CFMutableStringRef)str, NULL, kCFStringTransformStripDiacritics, NO);

    NSString *pinYin = [str capitalizedString];

    return [pinYin substringToIndex:1];

}


你可能感兴趣的:(iOS方法)