昨天發(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)查看官方文檔! 摘要: 閱讀全文























































輸出結(jié)果:hanzizhuanpinyin
轉(zhuǎn)換的正確率,還不錯(cuò)。
詳細(xì)請(qǐng)查看官方文檔! 摘要: 閱讀全文
| |||||||||
日 | 一 | 二 | 三 | 四 | 五 | 六 | |||
---|---|---|---|---|---|---|---|---|---|
31 | 1 | 2 | 3 | 4 | 5 | 6 | |||
7 | 8 | 9 | 10 | 11 | 12 | 13 | |||
14 | 15 | 16 | 17 | 18 | 19 | 20 | |||
21 | 22 | 23 | 24 | 25 | 26 | 27 | |||
28 | 29 | 30 | 1 | 2 | 3 | 4 | |||
5 | 6 | 7 | 8 | 9 | 10 | 11 |
沒(méi)有什么不可以承受,只是沒(méi)有落到自己身上。
沒(méi)有什么不可以成功,只是沒(méi)有真正的努力過(guò)。
常用鏈接
留言簿(2)
隨筆分類
隨筆檔案
最新隨筆
搜索
積分與排名
- 積分 - 7314
- 排名 - 2725
最新評(píng)論

- 1.?re: 漢字轉(zhuǎn)拼音(PinYin4j)
- 謝謝你,親,啊哈哈~
- --張志杰
- 2.?re: 漢字轉(zhuǎn)拼音(PinYin4j)
-
謝謝分享,的確挺好玩!不過(guò)第一句話有個(gè)錯(cuò)別字,嘻嘻........
<昨天發(fā)現(xiàn)一號(hào)玩的jar包> - --MMMM