package com.landtool.lanbase.common.utils; 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; /** * @author lanbase * @Description: TODO(中文转拼音工具) * @date 2017-9-26 10:09 */ public class PinyinUtils { /** * 将文字转为汉语拼音 * @param ChineseLanguage 要转成拼音的中文 */ private static String toHanyuPinyin(String ChineseLanguage, HanyuPinyinCaseType caseType){ char[] cl_chars = ChineseLanguage.trim().toCharArray(); String hanyupinyin = ""; HanyuPinyinOutputFormat defaultFormat = new HanyuPinyinOutputFormat(); defaultFormat.setCaseType(caseType); defaultFormat.setToneType(HanyuPinyinToneType.WITHOUT_TONE);// 不带声调 defaultFormat.setVCharType(HanyuPinyinVCharType.WITH_V) ; try { for (int i=0; i