Ren_XiaoGuang
BlogJava
首頁
新隨筆
聯(lián)系
聚合
管理
posts - 2, comments - 2, trackbacks - 0
漢字轉(zhuǎn)拼音(PinYin4j)
昨天發(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 on 2008-11-20 09:56
R_XiaoGuang
閱讀(3035)
評(píng)論(2)
編輯
收藏
所屬分類:
opensource
FeedBack:
#
re: 漢字轉(zhuǎn)拼音(PinYin4j)
2011-10-12 13:16 |
MMMM
謝謝分享,的確挺好玩!不過第一句話有個(gè)錯(cuò)別字,嘻嘻........
<昨天發(fā)現(xiàn)一號(hào)玩的jar包>
回復(fù)
更多評(píng)論
#
re: 漢字轉(zhuǎn)拼音(PinYin4j)
2012-06-19 10:21 |
張志杰
謝謝你,親,啊哈哈~
回復(fù)
更多評(píng)論
新用戶注冊(cè)
刷新評(píng)論列表
只有注冊(cè)用戶
登錄
后才能發(fā)表評(píng)論。
網(wǎng)站導(dǎo)航:
博客園
IT新聞
Chat2DB
C++博客
博問
管理
Copyright ©2025 R_XiaoGuang Powered By:
博客園
模板提供:
滬江博客
<
2011年10月
>
日
一
二
三
四
五
六
25
26
27
28
29
30
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
31
1
2
3
4
5
沒有什么不可以承受,只是沒有落到自己身上。
沒有什么不可以成功,只是沒有真正的努力過。
常用鏈接
我的隨筆
我的評(píng)論
我的參與
最新評(píng)論
留言簿
(2)
給我留言
查看公開留言
查看私人留言
隨筆分類
opensource(1)
Struts(2)
SVG
隨筆檔案
2008年11月 (1)
2008年9月 (1)
2008年7月 (1)
最新隨筆
1.?漢字轉(zhuǎn)拼音(PinYin4j)
2.?Struts 中跳轉(zhuǎn)后樣式表丟失問題解決
3.?MyEclipse 6.5注冊(cè)機(jī)(java源碼_轉(zhuǎn)載)
搜索
積分與排名
積分 - 7313
排名 - 2725
最新評(píng)論
1.?re: 漢字轉(zhuǎn)拼音(PinYin4j)
謝謝你,親,啊哈哈~
--張志杰
2.?re: 漢字轉(zhuǎn)拼音(PinYin4j)
謝謝分享,的確挺好玩!不過第一句話有個(gè)錯(cuò)別字,嘻嘻........
<昨天發(fā)現(xiàn)一號(hào)玩的jar包>
--MMMM
閱讀排行榜
1.?漢字轉(zhuǎn)拼音(PinYin4j)(3035)
2.?MyEclipse 6.5注冊(cè)機(jī)(java源碼_轉(zhuǎn)載)(2990)
3.?Struts 中跳轉(zhuǎn)后樣式表丟失問題解決(133)
評(píng)論排行榜
1.?漢字轉(zhuǎn)拼音(PinYin4j)(2)
2.?Struts 中跳轉(zhuǎn)后樣式表丟失問題解決(0)
3.?MyEclipse 6.5注冊(cè)機(jī)(java源碼_轉(zhuǎn)載)(0)
主站蜘蛛池模板:
讷河市
|
桐庐县
|
柳江县
|
亚东县
|
唐河县
|
历史
|
北流市
|
昔阳县
|
九江县
|
无棣县
|
灌阳县
|
武鸣县
|
永顺县
|
正宁县
|
富民县
|
潜江市
|
平潭县
|
常熟市
|
遵化市
|
米林县
|
渑池县
|
专栏
|
盐源县
|
广水市
|
拜城县
|
荆州市
|
清徐县
|
松潘县
|
右玉县
|
平邑县
|
河东区
|
祁门县
|
息烽县
|
泸西县
|
崇文区
|
饶阳县
|
长春市
|
阿尔山市
|
通化县
|
杭锦旗
|
赞皇县
|