转载自http://blog.csdn.net/kmyhy/article/details/54846361
+(NSString *) getFirstLetter:(NSString *) strInput{ if ([strInput length]) { NSMutableString *ms = [[NSMutableString alloc] initWithString:strInput]; // 1. kCFStringTransformMandarinLatin 表示中文转拉丁字母,NULL 表示转换范围为整个字符串 CFStringTransform((__bridge CFMutableStringRef)ms, NULL, kCFStringTransformMandarinLatin, NO); // 2. kCFStringTransformStripDiacritics,去掉音调 CFStringTransform((__bridge CFMutableStringRef)ms, 0, kCFStringTransformStripDiacritics, NO); // 3. 转换结果是按将个汉字的拼音以空格分隔的,我们将每个汉字的拼音按空格切开放到数组中 NSArray *pyArray = [ms componentsSeparatedByString:@" "]; if(pyArray && pyArray.count > 0){ ms = [[NSMutableString alloc] init]; // 4. 只取每个汉字的首字母 for (NSString *strTemp in pyArray) { [ms appendString:[strTemp substringToIndex:1]]; } return [ms uppercaseString]; } ms = nil; } return nil;}新闻热点
疑难解答