zoukankan      html  css  js  c++  java
  • ios汉字转拼音,支持多音节

    1 + (NSString *)transform:(NSString *)chinese
    2 {
    3     NSMutableString *pinyin = [chinese mutableCopy];
    4     CFStringTransform((__bridge CFMutableStringRef)pinyin, NULL, kCFStringTransformMandarinLatin, NO);
    5     CFStringTransform((__bridge CFMutableStringRef)pinyin, NULL, kCFStringTransformStripCombiningMarks, NO);
    6     NSLog(@"%@", pinyin);
    7     return [pinyin uppercaseString];
    8 }

    kCFStringTransformMandarinLatin方法转化出来的是带音标的拼音,如果需要去掉音标,则继续使用kCFStringTransformStripCombiningMarks方法即可。
    但是这种方式性能可能会比较差。推荐使用第三方的使用 -------------->>试试这个第三方:https://github.com/kimziv/PinYin4Objc,支持多音字


    下面自己做小Demo,可以 参考下面代码
    NSString *sourceText=@"我爱中文";
      HanyuPinyinOutputFormat *outputFormat=[[HanyuPinyinOutputFormat alloc] init];
      [outputFormat setToneType:ToneTypeWithoutTone];
      [outputFormat setVCharType:VCharTypeWithV];
      [outputFormat setCaseType:CaseTypeLowercase];    
      [PinyinHelper toHanyuPinyinStringWithNSString:sourceText 
                         withHanyuPinyinOutputFormat:outputFormat 
                                         withNSString:@" " 
                                         outputBlock:^(NSString *pinYin) {
          _outputTv.text=pinYin; //update ui
    
       }];
     
  • 相关阅读:
    Prometheus服务发现
    持久化查询
    PromQL进阶
    PromQL基础
    Prometheus概述
    监控系统概念
    zabbix5x解决中文字体问题
    allure 插件新手 demo
    关于时间复杂度~
    IIS发布网站Microsoft JET Database Engine 错误 '80004005'的解决办法,基于Access数据库
  • 原文地址:https://www.cnblogs.com/huangzhenwei/p/6027577.html
Copyright © 2011-2022 走看看