時々、この状況に遭遇し、特定の中国のピンイン、中国の略語、中国のイニシャルを入手する必要があります。以下に、中国のピンインの略語を入手する方法を紹介します。
1。プロジェクトの確立と構成
まず、Javaプロジェクトを作成し、新しいLIBSフォルダーを作成し、734A7099-4830-39F2-A136-0E850CCDCC7A.JARファイルを導入します。このステップは詳細に書く必要はないと信じています。スキップします。
2。中国のピニインを入手してください(次のような:広東省 - >広東省)
</pre> <pre name = "code"> <span style = "white-space:pre"> </span>/*** @param src変換する必要がある中国の文字列を取得* @return*/public static string getpingyin(string src){char [] t1 = null; t1 = src.tochararray(); string [] t2 = new String [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.tohanyupnyintringringringt1; T4 += T2 [0]; } else {t4 += java.lang.character.toString(t1 [i]); }} t4を返します。 } catch(badhanyupinyinoutputformatcombination e1){e1.printstacktrace(); } t4を返します。 } 3.中国の頭字語の略語を取得します(次のような:広東省 - > GDS)
</pre> <pre name = "code"> <span style = "white-space:pre"> </span>/*** @param str変換する必要がある中国語の文字列を取得* @return*/public static string getpinyinheadchar(string str){string convert = ""; for(int j = 0; j <str.length(); j ++){char word = str.charat(j); string [] pinyinarray = pinyinhelper.tohanyupinyinstringarray(word); if(pinyinarray!= null){convert += pinyinarray [0] .Charat(0); } else {convert += word; }} convertを返します。 } 4。中国の最初の手紙を入手して、大文字に変換します(広東省 - > gなど)
ステップ3 getpinyinheadcharメソッドを組み合わせる必要があります。コードは次のとおりです。
</pre> <pre name = "code"> <span style = "white-space:pre"> </span> string s = getPinyInHeadChar( "Guangdong州"); System.out.println( "Pinyin略語を取得:" + s); stringbuffer sb = new StringBuffer(s); if(sb.length()> 1){string ss = sb.delete(1、sb.length())。toString(); system.out.println( "最初の文字を取得:" + character.touppercase(ss.tochararray()[0]) + "");上記はこの記事のすべての内容です。みんなの学習に役立つことを願っています。誰もがwulin.comをもっとサポートすることを願っています。