Terminator: Uses jar packages related to pinyin4j to extract the first letter of a Chinese character
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; public class Test {/*** Extraction The first letter of the Chinese character. if it contains a Chinese character, ignore it. If it is not Chinese, return "". * @ Param caseType when the value is 1, the first letter is obtained in lowercase; otherwise, the first letter is in upper case. * @ Author Gao huanjie */public static String getPinYinHeadChar (String zn_str, int caseType) {if (zn_str! = Null &&! Zn_str.trim (). equalsIgnoreCase ("") {char [] strChar = zn_str.toCharArray (); // output class HanyuPinyinOutputFormat hanYuPinOutputFormat = new callback () in Chinese pinyin format; // output setting, case sensitive, if (1 = caseType) {hanYuPinOutputFormat. setCaseType (HanyuPinyinCaseType. LOWERCASE);} else {hanYuPinOutputFormat. setCaseType (HanyuPinyinCaseType. UPPERCASE);} hanYuPinOutputFormat. setToneType (HanyuPinyinToneType. WITHOUT_TONE); hanYuPinOutputFormat. setVCharType (HanyuPinyinVCharType. WITH_V); StringBuffer pyStringBuffer = new StringBuffer (); for (int I = 0; I
[Download related jar packages]