java汉字转换为全拼
来源:互联网 发布:淘宝企业店铺怎么注销 编辑:程序博客网 时间:2024/04/27 11:07
//需要 pinyin4j-2.5.0.jar jar包<pre name="code" class="java">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;/** * Created by zong on 2016/6/1. */public class Z_ChineseToPinyin { // 将汉字转换为全拼 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++) { strBuf.append(Integer.toHexString(bGBK[i] & 0xff)); } return strBuf.toString(); }}
0 0
- java汉字转换为全拼
- 汉字转换为全拼
- 将汉字转换为全拼
- java将汉字转换为全拼及返回中文的首字母
- 汉字转化为全拼
- 用Java转化汉字为拼音全拼
- 用Java转化汉字为拼音全拼
- 用Java转化汉字为拼音全拼
- 用Java转化汉字为拼音全拼
- 用Java转化汉字为拼音全拼
- 用Java转化汉字为拼音全拼
- 用Java转化汉字为拼音全拼
- 汉字与全拼的转换!
- c#实现汉字转换全拼
- 把汉字转换成拼音(全拼)
- asp.net 将中文汉字转换为英文首字母和将汉字转换为拼音全拼
- 终结者:借助pinyin4j相关jar包将汉字转换为全拼的拼音
- java 读取汉字全拼简写
- Android Studio 对GitHub开源项目的引用及导入
- i++与++i
- linux命令ps aux|grep xxx详解
- 借助 windows cmd 批量创建文件夹
- Windows进程控制
- java汉字转换为全拼
- nginx介绍
- Google Guava中Preconditions的用法,让前置条件判断变得更优雅
- hdu 5640(切蛋糕)
- Android Studio入门到精通
- 余额宝技术架构及演进
- gradle 打包
- leetcode编程笔记(一)——two sum
- Elasticsearch学习总结