程序里面用到了开源的包,可以将汉语转成全拼或者缩写,代码如下:
/**
* author:qiaolei
* 2010-6-25上午11:44:21create
*/
package com.sucre;
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 ChineseToEnglish {
// 将汉字转换为全拼
public static String getPingYin(String src){
char[] t1 = null;
t1=src.toCharArray();
String[] t2 = new String[t1.length];
HanyuPinyinOutputFormat t3 = new HanyuPinyinOutputFormat();
t3.setCaseType(HanyuPinyinCaseType.LOWERCASE);
t3.setToneType(HanyuPinyinToneType.WITHOUT_TONE);
t3.setVCharType(HanyuPinyinVCharType.WITH_V);
String t4="";
int t0=t1.length;
try {
for (int i=0;i<t0;i++)
{
//判断是否为汉字字符
if(java.lang.Character.toString(t1[i]).matches("[\\u4E00-\\u9FA5]+"))
{
t2 = PinyinHelper.toHanyuPinyinStringArray(t1[i], t3);
t4+=t2[0];
}
else
t4+=java.lang.Character.toString(t1[i]);
}
// System.out.println(t4);
return t4;
}
catch (BadHanyuPinyinOutputFormatCombination e1) {
e1.printStackTrace();
}
return t4;
}
// 返回中文的首字母
public static String getPinYinHeadChar(String str) {
String convert = "";
for (int j = 0; j < str.length(); j++) {
char word = str.charAt(j);
String[] pinyinArray = PinyinHelper.toHanyuPinyinStringArray(word);
if (pinyinArray != null) {
convert += pinyinArray[0].charAt(0);
}else {
convert += word;
}
}
return convert;
}
// 将字符串转移为ASCII码
public static String getCnASCII(String cnStr)
{
StringBuffer strBuf = new StringBuffer();
byte[] bGBK = cnStr.getBytes();
for(int i=0;i <bGBK.length;i++){
// System.out.println(Integer.toHexString(bGBK[i]&0xff));
strBuf.append(Integer.toHexString(bGBK[i]&0xff));
}
return strBuf.toString();
}
public static void main(String[] args) {
System.out.println(getPingYin("綦江县"));
System.out.println(getPinYinHeadChar("綦江县"));
System.out.println(getCnASCII("綦江县"));
}
结果如下:
qijiangxian
qjx
f4ebbdadcfd8
}
所需要的jar包见附件
分享到:
相关推荐
自定义函数,将汉字转换成每个汉语拼音的首字母
C#将汉字转换成全拼的拼音
拼音转换成汉字的好工具 拼音转换成汉字的好工具
将中文汉字转换成拼音(全拼) asp.net c#,winfrom asp.net 直接使用。
Oracle中进行汉字转换成拼音,通过参数不同可以返回拼音首字母或全拼: --调用方式: SELECT f_getSpell('江西') from dual; --返回 'jx' --SELECT f_getSpell('江西',0) from dual; --返回 'jiangxi'
oracle汉字转换成拼音首字母、全拼,各种转换类型比较齐全,oracle汉字转换五笔首字母链接https://blog.csdn.net/weixin_40912627/article/details/88710064
海鸥汉字转换成拼音全拼软件是一款Windows操作系统下的简单实用美观的汉字转换成拼音全拼软件。汉字转换成拼音全拼功能特色:一、所有功能集成在同一界面实现,易于操作和使
汉字转成拼音全拼 汉字转成拼音简拼 加解密函数 以及页面文本框的清空方法
在 pinyin.js 中有两种转换: 全拼转换 和 拼音首字母转换。全拼转换时可以使用不同的 汉字库js 得到你想要的带或不带声调的全拼。 拼音首字母转换则随便使用哪种汉字库js了。hz.js 汉字拼音带声调。如: 贝bèi 。 ...
将任意个汉字转换成汉语拼音全拼或第一个字母的JAVA程序
汉字转换成拼音全拼也能转换成首写字母,如有需要联系本人.
将汉字转化为拼音的JavaScript插件,并支持多音字。
主要介绍了Mysql中文汉字转拼音的实现,并且每个汉字会转换全拼,使用Mysql自定义函数实现,需要的朋友可以参考下
测试代码: var anhui = "安徽"; //获得全拼 pinyin.getFullChars(anhui); //获得首拼 pinyin.getCamelChars(anhui);
汉字转换拼音、拼音首字母工具类!很好,很实用,可以把中文转换成汉语拼音全拼或者拼音首字母!
网上查询了很多汉字转拼音的方案,一种是用VBA实现的,另一种是只能转汉字首字母,都不是我需要的方案,因此结VBA的方式,用Delphi实现汉字转拼音全拼的方法,对excel文件中的中文转成拼音后,写入excel其他列中,并...
C#汉字转拼音静态类,包括功能全拼和缩写,方法全部是静态的 //13份WPF经典开发教程 http://download.csdn.net/album/detail/1115 //C#资料合辑二[C#桌面编程入门篇] http://download.csdn.net/album/detail/957 /...
可以把中文转换成拼音,支持首字母和全拼,比较简单,实用就行,支持中英文字符混排等。字库为unicode编码,可以维护,D7下通过。
汉字转拼音全拼读音发音 汉字转拼音全拼读音发音 汉字转拼音全拼读音发音
可以将oracle中保存的中文转换成拼音首字母,转换成全拼等