获取汉字的拼音#import <Foundation/Foundation.h>
@interface NSString (Utils)
/**
* 汉字的拼音
*
* @return 拼音
*/
- (NSString *
)pinyin;
@end
#import "NSString+Utils.h"
@implementation NSString (Utils)
//汉字的拼音
- (NSString *
)pinyin{
NSMutableString *str =
[self mutableCopy];
CFStringTransform(( CFMutableStringRef)str, NULL, kCFStringTransformMandarinLatin, NO);
CFStringTransform((CFMutableStringRef)str, NULL, kCFStringTransformStripDiacritics, NO);
return [str stringByReplacingOccurrencesOfString:
@" " withString:
@""];
}
@end