Terminator: Uses jar packages related to pinyin4j to extract the first letter of a Chinese character

Source: Internet
Author: User

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]
 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.