The Code is as follows:
1 import net. sourceForge. pinyin4j. pinyinhelper; 2 Import net. sourceForge. pinyin4j. format. hanyupinyincasetype; 3 Import net. sourceForge. pinyin4j. format. hanyupinyinoutputformat; 4 Import net. sourceForge. pinyin4j. format. hanyupinyintonetype; 5 import net. sourceForge. pinyin4j. format. hanyupinyinvchartype; 6 public class spellhelper {7 // convert Chinese to English 8 public static string getename (string name) 9 {10 hanyupinyinyinoutputformat pyformat = new hanyupinyinoutputformat (); 11 pyformat. setcasetype (hanyupinyincasetype. lowercase); 12 pyformat. settonetype (hanyupinyintonetype. without_tone); 13 pyformat. setvchartype (hanyupinyinvchartype. with_v); 14 15 return pinyinhelper. tohanyupinyinstring (name, pyformat, ""); 16} 17 18 // The first letter of the last name and name must be in uppercase 19 public static string getupename (string name) {20 char [] STRs = Name. tochararray (); 21 string newname = NULL; 22 23 // name length 24 if (STRs. length = 2) {25 newname = toupcase (getename ("" + STRs [0]) + "" 26 + toupcase (getename ("" + STRs [1]); 27} else if (STRs. length = 3) 28 {29 newname = toupcase (getename ("" + STRs [0]) + "" 30 + toupcase (getename ("" + STRs [1] + STRs [2]); 31} 32 else if (STRs. length = 4) 33 {34 newname = toupcase (getename ("" + STRs [0] + STRs [1]) + "" 35 + toupcase (getename ("" + STRs [2] + STRs [3]); 36} else 37 {38 newname = toupcase (getename (name )); 39} 40 return newname; 41} 42 43 // upper letter 44 Private Static string toupcase (string Str) {45 stringbuffer newstr = new stringbuffer (); 46 newstr. append (Str. substring (0, 1 )). touppercase ()). append (47 Str. substring (1, str. length (); 48 49 return newstr. tostring (); 50} 51 public static void main (string [] ARGs) {52 system. out. println (getupename ("Li Yuchun"); 53 54} 55 56}