Give us a few ways to get the first pinyin, all pinyin, and the first capitalization of the Chinese alphabet:
We need to use a foreign library, Pinyin4j-2.5.0.jar.
Everyone can download their own online or to share with me:
This one's got to share. Pinyin4j-2.5.0.jar: The library can be downloaded directly
Below is the use of the library, several examples of use:
"First Pinyin capitalization"
public static string Getalpha (String chines) {
string pinyinname = "";
char[] Namechar = Chines.tochararray ();
hanyupinyinoutputformat DefaultFormat = new Hanyupinyinoutputformat ();
defaultformat.setcasetype (hanyupinyincasetype.uppercase);
defaultformat.settonetype (Hanyupinyintonetype.without_tone);
for (int i = 0; i < namechar.length; i++) {
if (Namechar[i] >) {
& Nbsp; try {
pinyinname + = Pinyinhelper.tohanyupinyinstringarray ( Namechar[i], DefaultFormat) [0].charat (0);
} catch (Badhanyupinyinoutputformatcombination e) {
E.printstacktrace ();
}
} else {
pinyinname + = Namechar[i];
}
}
return pinyinname;
}
Full Pinyin
public static string Getpingyin (string inputstring) {
Hanyupinyinoutputformat format = new Hanyupinyinoutputformat ();
Format.setcasetype (hanyupinyincasetype.lowercase);
Format.settonetype (Hanyupinyintonetype.without_tone);
Format.setvchartype (HANYUPINYINVCHARTYPE.WITH_V);
char[] input = Inputstring.trim (). ToCharArray ();
String output = "";
try {
for (int i = 0; i < input.length; i++) {
if (java.lang.Character.toString (Input[i]). Matches ("[\\u4e00-\\u9fa5]+")) {
string[] temp = Pinyinhelper.tohanyupinyinstringarray (input[i], format);
Output + = Temp[0];
} else
Output + = java.lang.Character.toString (Input[i]);
}
} catch (Badhanyupinyinoutputformatcombination e) {
E.printstacktrace ();
}
return output;
}
First Pinyin
public static string Convertertofirstspell (String chines) {
String pinyinname = "";
char[] Namechar = Chines.tochararray ();
Hanyupinyinoutputformat DefaultFormat = new Hanyupinyinoutputformat ();
Defaultformat.setcasetype (hanyupinyincasetype.uppercase);
Defaultformat.settonetype (Hanyupinyintonetype.without_tone);
for (int i = 0; i < namechar.length; i++) {
if (Namechar[i] > 128) {
try {
Pinyinname + = Pinyinhelper.tohanyupinyinstringarray (Namechar[i], DefaultFormat) [0].charat (0);
} catch (Badhanyupinyinoutputformatcombination e) {
E.printstacktrace ();
}
} else {
Pinyinname + = Namechar[i];
}
}
return pinyinname;
}
}
This article is from the "Java" blog, so be sure to keep this source http://10594050.blog.51cto.com/10584050/1732349
Adnroid Java to get the first pinyin of Chinese characters, all pinyin, uppercase Pinyin