iOS 汉字的拼音

mac2024-11-27  47

获取汉字的拼音#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

 

最新回复(0)