汉字转拼音
来源:互联网 发布:js 数组长度 编辑:程序博客网 时间:2024/06/04 19:51
下载jar
点击下载pinyin4j
代码
public class ChineseToPinYin { public static String getPinYin(String inputString) { HanyuPinyinOutputFormat format = new HanyuPinyinOutputFormat(); //大小写格式化 format.setCaseType(HanyuPinyinCaseType.LOWERCASE); //是否显示声调 format.setToneType(HanyuPinyinToneType.WITHOUT_TONE); //碰到unicode的ü 、v和 u时的显示方式 format.setVCharType(HanyuPinyinVCharType.WITH_V); char[] input = inputString.trim().toCharArray(); StringBuilder output = new StringBuilder(""); try { for (int i = 0; i < input.length; i++) { if (Character.toString(input[i]).matches("[\u4E00-\u9FA5]+")) { String[] temp = PinyinHelper.toHanyuPinyinStringArray(input[i], format); output.append(temp[0]); System.out.println(temp[0]); } else { output.append(Character.toString(input[i])); } } } catch (BadHanyuPinyinOutputFormatCombination e) { } return output.toString(); } public static void main(String[] args) { String chs = "单田芳"; System.out.println(chs); System.out.println(getPinYin(chs)); }}
爱学习的朋友们加 刚建的qq群交流学习<程序员之家 227493974>
0 0
- 汉字转拼音
- 汉字转拼音缩写
- 汉字转拼音缩写
- 实用汉字转拼音
- 汉字转拼音
- 汉字转拼音 asp
- 汉字转拼音缩写
- 汉字转拼音
- 汉字转拼音缩写
- 汉字转拼音
- PHP汉字转拼音
- PHP汉字转拼音
- php汉字转拼音
- java 汉字转拼音
- 汉字转拼音(C#)
- VBS 汉字转拼音
- 汉字转拼音
- 汉字转拼音
- Muduo库的框架剖析及总结(一)
- Emacs用Magit管理git项目
- C++运算符的重载
- HDU 1007 Quoit Design 最小点对基础模板
- tomcat目录结构及配置文件说明
- 汉字转拼音
- java网络通讯(UDP与TCP)
- poj 3233 Matrix Power Series 二分求和式
- 用刚学的html为女朋友做个生日礼物
- 数据结构实验之排序三:bucket sort
- day8-6(一)
- hdu1013 Digital Roots
- Android-Universal-Image-Loader 图片加载库 详细分析
- 系统卸掉之后开机启动仍有该系统的索引的解决办法_win8.1卸掉ubuntu