您的当前位置:首页正文

苹果自带拼音转换方法

2024-11-12 来源:个人技术集锦


 1 - (NSString *)getPinYinFrom:(NSString *)chinese
2 { 3 CFMutableStringRef string = CFStringCreateMutableCopy(NULL, 0, (__bridge CFMutableStringRef)[NSMutableString stringWithString:chinese]); 4 CFStringTransform(string, NULL, kCFStringTransformMandarinLatin, NO); 5 CFStringTransform(string, NULL, kCFStringTransformStripDiacritics, NO); 6 7 NSMutableString *aNSString = (__bridge NSMutableString *)string; 8 NSString *finalString = [aNSString stringByReplacingOccurrencesOfString:[NSString stringWithFormat:@"%c", 32] withString:@""]; 9 10 NSLog(@"%@", finalString);11 return finalString;



Top