I now have more than 3,000 data in the Database Area table, now the demand is to convert each line of records in the name of the region into English (that is Hanyu Pinyin), while saving up, a little more intuitive
I would like to ask, there is no Chinese language library, I write a PHP program, the Chinese into pinyin, and then through the SQL statement Bulk INSERT, can not be a line to change it.
What can we do? Please answer
Reply content:
I now have more than 3,000 data in the Database Area table, now the demand is to convert each line of records in the name of the region into English (that is Hanyu Pinyin), while saving up, a little more intuitive
I would like to ask, there is no Chinese language library, I write a PHP program, the Chinese into pinyin, and then through the SQL statement Bulk INSERT, can not be a line to change it.
What can we do? Please answer
1, the project needs to put in Pinyin4j-2.5.0.jar, can be downloaded online, here does not provide download address 2, code: Import Net.sourceforge.pinyin4j.pinyinhelper;import Net.sourceforge.pinyin4j.format.hanyupinyincasetype;import Net.sourceforge.pinyin4j.format.hanyupinyinoutputformat;import Net.sourceforge.pinyin4j.format.hanyupinyintonetype;import net.sourceforge.pinyin4j.format.exception.badhanyupinyinoutputformatcombination;/** * Kanji Conversion bit Hanyu Pinyin, English characters unchanged * */Public Class Cn2spell {/** * Kanji conversion bit initials, English characters unchanged * @param chines kanji * @return Pinyin */Public St Atic string Convertertofirstspell (String chines) {string pinyinname = ""; char[] Namechar = Chines.tochararray (); Hanyupinyinoutputformat DefaultFormat = new Hanyupinyinoutputformat (); Defaultformat.setcasetype (hanyupinyincasetype.lowercase); 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; }/** * Chinese pinyin, English characters unchanged * @param chines kanji * @return Pinyin */public static String Conver Tertospell (String chines) {string pinyinname = ""; char[] Namechar = Chines.tochararray (); Hanyupinyinoutputformat DefaultFormat = new Hanyupinyinoutputformat (); Defaultformat.setcasetype (hanyupinyincasetype.lowercase); Defaultformat.settonetype (Hanyupinyintonetype.without_tone); for (int i = 0; i < namechar.length; i++) {if (Namechar[i] > +) {try { PinyinName + = Pinyinhelper.tohanyupinyinstringarray (Namechar[i], DefaultFormat) [0]; } catch (Badhanyupinyinoutputformatcombination e) {e.printstacktrace (); }}else{Pinyinname + = Namechar[i]; }} return pinyinname; } public static void Main (string[] args) {System.out.println (Convertertofirstspell ("Welcome to Java World")); System.out.println (Convertertospell ("Welcome to Java World")); } }
Https://github.com/overtrue/p ...