//将汉字转换为全拼
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) {
String cnStr = "中华人民共和国";
System.out.println(getPingYin(cnStr));
System.out.println(getPinYinHeadChar(cnStr));
}
}
下面为结果:
zhonghuarenmingongheguo
zhrmghg
分享到:
相关推荐
网上传的postgreSQL汉字转拼音的方法,是针对9.3的版本(相信你要是8.4的也搜到了但不能直接用,才来看我的),尝试了8.4的版本来做拼音处理。发现网上的《postgreSQL汉字转拼音》里面坑比较多,尝试纠正了一下,发...
C++,采用“拼音-中文”的数据字典的方式实现中文汉字转拼音,兼容多音字,字典为txt,后期可拓展易维护。在STL的map中查找效率16毫秒左右。
主要介绍了Mysql中文汉字转拼音的实现,并且每个汉字会转换全拼,使用Mysql自定义函数实现,需要的朋友可以参考下
C#汉字转拼音(npinyin)将中文转换成拼音全文或首字母
// 简单的高效的汉字转拼音、拼音转汉字类 // 包含20441个汉字26821拼音转换库文件,字库基本是网上最全的了,当然万一发现少了可以自己加入到字库中,一行一条记录加入到文本文件中即可,非常简单 // 算法方面没有...
支持2万+汉字转拼音
java汉字转拼音,android汉字转拼音,汉字转拼音首字母,汉字转ASCII
Java汉字转拼音(支持多音字)
Qt C++ 汉字转拼音与首字母,用Qt 5.5亲测可用
JS汉字转拼音,字母大小写转换,可直接使用的汉字转拼音JS
SQL中将汉字转换成拼音,这里是转换汉字首拼音,如果需要全部转换,在以下程序中稍微改几个数字就可以了
.NET实现汉字转拼音,汉字转拼音,语言转换 .NET实现汉字转拼音,汉字转拼音,语言转换 .NET实现汉字转拼音,汉字转拼音,语言转换 .NET实现汉字转拼音,汉字转拼音,语言转换
中文转拼音的js控件,引用非常简单。
汉字转拼音声母首字母 dll delphi
Java 中文转拼音/中文转五笔/汉字转拼音/汉字转五笔 字典. 通过 https://blog.csdn.net/qcl108/article/details/100981774 提供的 Java代码使用.
汉字转拼音 asp 文件汉字转拼音 asp 文件汉字转拼音 asp 文件
sql 汉字转拼音首字母 代码 function --汉字转拼音首字母sql Create FUNCTION dbo.fnpbGetPYFirstLetter ( @str NVARCHAR(4000) )
支持2万+汉字转拼音首字母
Java实现汉字转拼音功能,包括首字母和全拼,为大家减少时间,为此提供便捷。
文件里面已弄了使用说明,转换比较全面,已经开发和测试。可用于后台的URL的路径使用,以及其它方面的一些转换使用,详情自己挖掘...