Ren_XiaoGuang
BlogJava
首頁
新隨筆
聯系
聚合
管理
posts - 2, comments - 2, trackbacks - 0
漢字轉拼音(PinYin4j)
昨天發現一號玩的jar包(pinyin4j-2.5.0.jar),可以把漢字轉為拼音。可在
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()];
/** */
/**
* 設置輸出格式
*/
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(
"
漢字轉拼音
"
));
}
}
輸出結果:
hanzizhuanpinyin
轉換的正確率,還不錯。
詳細請查看官方文檔!
posted on 2008-11-20 09:56
R_XiaoGuang
閱讀(3035)
評論(2)
編輯
收藏
所屬分類:
opensource
FeedBack:
#
re: 漢字轉拼音(PinYin4j)
2011-10-12 13:16 |
MMMM
謝謝分享,的確挺好玩!不過第一句話有個錯別字,嘻嘻........
<昨天發現一號玩的jar包>
回復
更多評論
#
re: 漢字轉拼音(PinYin4j)
2012-06-19 10:21 |
張志杰
謝謝你,親,啊哈哈~
回復
更多評論
新用戶注冊
刷新評論列表
只有注冊用戶
登錄
后才能發表評論。
網站導航:
博客園
IT新聞
Chat2DB
C++博客
博問
管理
Copyright ©2025 R_XiaoGuang Powered By:
博客園
模板提供:
滬江博客
<
2008年11月
>
日
一
二
三
四
五
六
26
27
28
29
30
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
沒有什么不可以承受,只是沒有落到自己身上。
沒有什么不可以成功,只是沒有真正的努力過。
常用鏈接
我的隨筆
我的評論
我的參與
最新評論
留言簿
(2)
給我留言
查看公開留言
查看私人留言
隨筆分類
opensource(1)
Struts(2)
SVG
隨筆檔案
2008年11月 (1)
2008年9月 (1)
2008年7月 (1)
最新隨筆
1.?漢字轉拼音(PinYin4j)
2.?Struts 中跳轉后樣式表丟失問題解決
3.?MyEclipse 6.5注冊機(java源碼_轉載)
搜索
積分與排名
積分 - 7314
排名 - 2725
最新評論
1.?re: 漢字轉拼音(PinYin4j)
謝謝你,親,啊哈哈~
--張志杰
2.?re: 漢字轉拼音(PinYin4j)
謝謝分享,的確挺好玩!不過第一句話有個錯別字,嘻嘻........
<昨天發現一號玩的jar包>
--MMMM
閱讀排行榜
1.?漢字轉拼音(PinYin4j)(3035)
2.?MyEclipse 6.5注冊機(java源碼_轉載)(2991)
3.?Struts 中跳轉后樣式表丟失問題解決(133)
評論排行榜
1.?漢字轉拼音(PinYin4j)(2)
2.?Struts 中跳轉后樣式表丟失問題解決(0)
3.?MyEclipse 6.5注冊機(java源碼_轉載)(0)
主站蜘蛛池模板:
西峡县
|
衢州市
|
新河县
|
武城县
|
新民市
|
西和县
|
开原市
|
老河口市
|
扶风县
|
台北县
|
石河子市
|
阿鲁科尔沁旗
|
文昌市
|
唐河县
|
河南省
|
通城县
|
固始县
|
虹口区
|
昌邑市
|
沙田区
|
蕲春县
|
鄢陵县
|
疏勒县
|
岳阳县
|
临汾市
|
年辖:市辖区
|
新龙县
|
洮南市
|
阳春市
|
若羌县
|
晋中市
|
吉安县
|
邵阳县
|
曲水县
|
彰化县
|
邯郸市
|
大港区
|
岳普湖县
|
清河县
|
台东县
|
塔城市
|