posts - 2,  comments - 2,  trackbacks - 0
            2008年9月20日
                昨天發(fā)現(xiàn)一號(hào)玩的jar包(pinyin4j-2.5.0.jar),可以把漢字轉(zhuǎn)為拼音。可在http://pinyin4j.sourceforge.net/下載。下面是我做的一個(gè)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)換的正確率,還不錯(cuò)。
          詳細(xì)請(qǐng)查看官方文檔!
          posted @ 2008-11-20 09:56 R_XiaoGuang 閱讀(3036) | 評(píng)論 (2)編輯 收藏
               摘要:   閱讀全文
          posted @ 2008-09-20 07:31 R_XiaoGuang 閱讀(133) | 評(píng)論 (0)編輯 收藏
          <2008年9月>
          31123456
          78910111213
          14151617181920
          21222324252627
          2829301234
          567891011

          沒(méi)有什么不可以承受,只是沒(méi)有落到自己身上。

          沒(méi)有什么不可以成功,只是沒(méi)有真正的努力過(guò)。

           

          常用鏈接

          留言簿(2)

          隨筆分類

          隨筆檔案

          最新隨筆

          搜索

          •  

          積分與排名

          • 積分 - 7314
          • 排名 - 2725

          最新評(píng)論

          閱讀排行榜

          評(píng)論排行榜

          主站蜘蛛池模板: 班戈县| 龙川县| 容城县| 珠海市| 紫阳县| 丰顺县| 贺兰县| 册亨县| 衡阳县| 德江县| 耿马| 方正县| 涟水县| 上林县| 象州县| 田东县| 淳安县| 临安市| 贵南县| 万州区| 砀山县| 台州市| 辽阳市| 青铜峡市| 镇原县| 阳新县| 鄂尔多斯市| 化州市| 垦利县| 温宿县| 肥西县| 桑日县| 灵璧县| 揭阳市| 商南县| 泽州县| 芜湖市| 涪陵区| 申扎县| 资中县| 会东县|