posts - 2,  comments - 2,  trackbacks - 0
                昨天發(fā)現(xiàn)一號玩的jar包(pinyin4j-2.5.0.jar),可以把漢字轉(zhuǎn)為拼音??稍?a >http://pinyin4j.sourceforge.net/下載。下面是我做的一個Demo

          import net.sourceforge.pinyin4j.PinyinHelper;
          import net.sourceforge.pinyin4j.format.HanyuPinyinCaseType;
          import net.sourceforge.pinyin4j.format.HanyuPinyinOutputFormat;
          import net.sourceforge.pinyin4j.format.HanyuPinyinToneType;
          import net.sourceforge.pinyin4j.format.HanyuPinyinVCharType;
          import net.sourceforge.pinyin4j.format.exception.BadHanyuPinyinOutputFormatCombination;
          public class HanZiToPinYin {


              
          public static  String toPinYin(String hanzhis){
                  CharSequence s
          = hanzhis;
                  
                  
          char [] hanzhi=new char[s.length()];
                  
          for(int i=0;i<s.length();i++){
                      hanzhi[i]
          =s.charAt(i);
                  }

                  
                  
          char [] t1 =hanzhi; 
                  String[] t2 
          = new String[s.length()];
                  
          /**
                   * 設(shè)置輸出格式
                   
          */

                  net.sourceforge.pinyin4j.format.HanyuPinyinOutputFormat t3 
          = new
                  HanyuPinyinOutputFormat();
                  t3.setCaseType(HanyuPinyinCaseType.UPPERCASE);
                  t3.setToneType(HanyuPinyinToneType.WITHOUT_TONE);
                  t3.setVCharType(HanyuPinyinVCharType.WITH_V);
                  
                  
          int t0=t1.length;
                  String py 
          = "";
                  
          try {
                      
          for (int i=0;i<t0;i++)
                      
          {
                          t2 
          = PinyinHelper.toHanyuPinyinStringArray(t1[i], t3);
                          py
          =py+t2[0].toString();
                              }

                  }

                  
          catch (BadHanyuPinyinOutputFormatCombination e1) {
                      e1.printStackTrace();
                  }

                  
                  
          return py.trim();
                  }

              
              
              
              
              
          public static void main(String[] args) {
                  
                  System.err.println(ToPinYin.toPinYing(
          "漢字轉(zhuǎn)拼音"));
              }

           
          }


          輸出結(jié)果:hanzizhuanpinyin
                  轉(zhuǎn)換的正確率,還不錯。
          詳細(xì)請查看官方文檔!
          posted on 2008-11-20 09:56 R_XiaoGuang 閱讀(3035) 評論(2)  編輯  收藏 所屬分類: opensource

          FeedBack:
          # re: 漢字轉(zhuǎn)拼音(PinYin4j)
          2011-10-12 13:16 | MMMM
          謝謝分享,的確挺好玩!不過第一句話有個錯別字,嘻嘻........
          <昨天發(fā)現(xiàn)一號玩的jar包>  回復(fù)  更多評論
            
          # re: 漢字轉(zhuǎn)拼音(PinYin4j)
          2012-06-19 10:21 | 張志杰
          謝謝你,親,啊哈哈~  回復(fù)  更多評論
            

          只有注冊用戶登錄后才能發(fā)表評論。


          網(wǎng)站導(dǎo)航:
           
          <2011年10月>
          2526272829301
          2345678
          9101112131415
          16171819202122
          23242526272829
          303112345

          沒有什么不可以承受,只是沒有落到自己身上。

          沒有什么不可以成功,只是沒有真正的努力過。

           

          常用鏈接

          留言簿(2)

          隨筆分類

          隨筆檔案

          最新隨筆

          搜索

          •  

          積分與排名

          • 積分 - 7314
          • 排名 - 2725

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 息烽县| 景德镇市| 长子县| 溧水县| 康定县| 中宁县| 乌什县| 阿克陶县| 平阳县| 长治市| 闸北区| 湟中县| 清流县| 屏东市| 五原县| 邵东县| 尼玛县| 定州市| 尉犁县| 博乐市| 文水县| 宁津县| 高唐县| 太原市| 娱乐| 阿坝| 深圳市| 二连浩特市| 侯马市| 云林县| 巧家县| 大余县| 磴口县| 炉霍县| 肥乡县| 遂平县| 沙田区| 英德市| 彰化市| 莎车县| 昔阳县|