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; 12 }
以上由群内人人网的老王提供,我先 mark