이 기사에서는 중국어가 중국인 Pinyin으로 전환하는 Java의 방법에 대해 설명합니다. 다음과 같이 참조에 대해 공유하십시오.
나는 인터넷을 돌아 다니며 우연히 Pinyin4J라는 매우 흥미로운 가제트를 보았다. 중국어를 중국인 Pinyin으로 전환 할 수 있습니다. 그의 말을 사용하고 루센과 중국 분사와 결합하여 Google과 유사한 기능을 만들어 전체 텍스트 검색을 위해 중국 Pinyin을 입력 할 수 있습니다. 구현 된 코드는 다음과 같습니다
PACKING PINYIN4J; import net.sourceforge.pinyin4j.pinyinHelper; import net.sourceforge.pinyin4j.format.hanyUpinyIncasetype; import net.sourceforge.pinyin4j.format.hanyUpinyInoutputformat; import net.sourceforge.pinyin4j.hanyUpceforge.pinyin4j.hanyUpineTyneType net.sourceforge.pinyin4j.format.hanyUpinyInvChartype; import net.sourceforge.pinyin4j.exception.badhanyUpinyInoutputformatcombination; public class pinyin4jtest {public static void main (string argsp []) {string output = pinyin4jtest (hello) null); System.out.println (출력); } catch (badhanyUpinyInoutputformatcombination e) {// todo 자동 생성 캐치 블록 e.printstacktrace (); }} /*** @parm inputcn 중국어 문자열 입력* @parm seg delimiter 중국어 pinyin** hanyupinyinoutputformat을 제공 할 때* hanyupinyinoutputformat* hanyupinyincasetype : 입력의 결과가 문체인지 에스 가방 : 곡물의 소문자 : hanyupinyintonetype를 나타냅니다. ye1 1-4와 같은 톤을 나타냅니다. 이는 1-4 사운드를 의미합니다. if (seg == null) seg = ""; hanyUpinyInoutputformat format = new hanyUpinyInoutputformat (); format.setCaseType (hanyUpinyIncasetype.lowercase); format.settoneType (hanyuPinyIntonEtype.without_tone); format.setvchartype (hanyupinyinvchartype.with_v); 문자열 출력 = ""; 문자열 [] temp = 새 문자열 [10]; for (int i = 0; i <inputarray.length; i ++) {temp = pinyinHelper.toHanyUpinyInstringArray (inputArray [i], format); // 입력 한 중국어가 다성 문자 인 경우, 다른 발음이 순서대로 온도 []에 배치됩니다. 그것이 다성 문자가 아닌 경우, 온도 [0]의 값 만 (int j = 0; j <temp.length; j ++) {output += temp [j] +seg; }} return output; }}이 기사가 모든 사람의 Java 프로그래밍에 도움이되기를 바랍니다.