때때로 우리는이 상황에 직면하고, 특정 중국인 Pinyin, 중국어 약어 및 중국 이니셜을 얻어야합니다. 아래에서는 중국 Pinyin 약어를 얻는 방법을 소개하겠습니다.
1. 프로젝트 설정 및 구성
먼저 Java 프로젝트를 만들고 새로운 Libs 폴더를 만들고 734A7099-4830-39F2-A136-0E850CCDCC7A.JAR 파일을 소개합니다. 나는이 단계가 자세히 작성 될 필요가 없다고 생각합니다.
2. 중국인 Pinyin을 얻으십시오 (예 : Guangdong Province-> Guangdongsheng)
</pre> <pre name = "code"> <span style = "white-space : pre"> </span>/*** 전체 중국어 철자를 얻으십시오* @param src 전환 해야하는 중국어 문자열* @return*/public static string getpingyin (문자열 src) {char [] t1 = null; t1 = src.tochararray (); 문자열 [] t2 = 새 문자열 [t1.length]; hanyUpinyInoutputFormat t3 = new hanyUpinyInoutputformat (); t3.setCaseType (hanyupinyincasetype.lowercase); t3.settoneType (hanyUpinyIntonEtype.without_tone); t3.setvchartype (hanyupinyinvchartype.with_v); 문자열 t4 = ""; int t0 = t1.length; try {for (int i = 0; i <t0; i ++) {// 중국어인지 결정 (java.lang.character.tostring (t1 [i]). 일치 ( "[// u4e00-// u9fa5]+") {t2 = pinyinhelper.tohanyupininpininstray (t3); T4 += T2 [0]; } else {t4 += java.lang.character.toString (t1 [i]); }} return t4; } catch (badhanyUpinyInoutputformatcombination e1) {e1.printstacktrace (); } return t4; } 3. 중국어 약어의 약어를 얻으십시오 (예 : Guangdong Province-> GDS)
</pre> <pre name = "code"> <span style = "white-space : pre"> </span>/*** 중국 초기 문자를 얻으십시오* @param str 전환 해야하는 중국 문자열*/public string getPinyInbatch (String str) {String convert = ""; for (int j = 0; j <st.length (); j ++) {char word = str.charat (j); 문자열 [] pinyinarray = pinyinHelper.toHanyUpinyInstringArray (Word); if (pinyinarray! = null) {convert += pinyinarray [0] .charat (0); } else {convert += Word; }} 반환 변환; } 4. 중국 초기 편지를 가져 와서 대문자로 전환하십시오 (예 : Guangdong Province-> G)
3 단계 getPinyInbatchchar 메서드를 결합해야합니다. 코드는 다음과 같습니다.
</pre> <pre name = "code"> <span style = "white-space : pre"> </span> string s = getPinyInbatch ( "Guangdong Province"); System.out.println ( "Pinyin 약어 가져 오기 :" + s); StringBuffer SB = New StringBuffer (S); if (sb.length ()> 1) {문자열 ss = sb.delete (1, sb.length ()). toString (); System.out.println ( "초기 문자 가져 오기 :" + arribute.touppercase (ss.tochararray () [0]) + ");위는이 기사의 모든 내용입니다. 모든 사람의 학습에 도움이되기를 바랍니다. 모든 사람이 wulin.com을 더 지원하기를 바랍니다.