当前位置:Gxl网 > 互联网 > 中文转拼音

中文转拼音

时间:2021-07-01 10:21:17 帮助过:1人阅读

- (NSString *)getPinYinFrom:(NSString *)chinese
{
    CFMutableStringRef string = CFStringCreateMutableCopy(NULL, 0, (__bridge CFMutableStringRef)[NSMutableString stringWithString:chinese]);
    CFStringTransform(string, NULL, kCFStringTransformMandarinLatin, NO);
    CFStringTransform(string, NULL, kCFStringTransformStripDiacritics, NO);

    NSMutableString *aNSString = (__bridge NSMutableString *)string;
    NSString *finalString = [aNSString stringByReplacingOccurrencesOfString:[NSString stringWithFormat:@"%c", 32] withString:@""];

    NSLog(@"%@", finalString);
    return finalString;
 }

 

相关教程