汉语拼音简拼 用到的jar包:(自己到官网下载吧,我实在弄不进来抱歉)
java详细代码:
package Pinyin;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;//汉字的汉语拼音简拼 就是一个类的方法学习public class Spell {public static void main(String[] args) {String str="李洪涛L";//拼音输出格式HanyuPinyinOutputFormat fmt=new HanyuPinyinOutputFormat();//大小写fmt.setCaseType(HanyuPinyinCaseType.LOWERCASE);//声调fmt.setToneType(HanyuPinyinToneType.WITHOUT_TONE);//将ǖ改成vfmt.setVCharType(HanyuPinyinVCharType.WITH_V);//每个汉字生成拼音后用ps数组接收String[] ps=null;String result="";//生成拼音for (int i = 0; i <str.length() ; i++) {try{//将制定汉字转换成拼音格式输出ps= PinyinHelper.toHanyuPinyinStringArray(str.charAt(i),fmt);}catch (Exception e){e.printStackTrace();}if(ps!=null){//简拼result+=ps[0].charAt(0);}else{//如果是字母 不是汉字的时候不用转换直接输出result+=str.charAt(i);}}System.out.println(result);}}
如果觉得《汉语拼音检索 简拼 java》对你有帮助,请点赞、收藏,并留下你的观点哦!