Use Chinese characters and pinyin for Java

Source: Internet
Author: User

Public class stringtools {
Public stringtools (){
}
// Obtain the pinyin code
Public String getpinym (string ){
// Chinese character location code
Int li_secposvalue [] = {1601,163 7, 1833,207 8, 2274,230 2, 2433,259 4,
2787,310 6, 3212,347 2, 3635,372 2, 3730,385 8,
4027,408 6, 4390,455 8, 4684,492 5, 5249,559 0 };
// Stores the pronunciation of the starting location code corresponding to different pronunciations of the first-level Chinese Character of the National Standard
Char lc_firstletter [] = {'A', 'B', 'C', 'D', 'E', 'F', 'G', 'h ', 'J ',
'K', 'l', 'M', 'n', 'O', 'P', 'Q', 'R','s ',
'T', 'w', 'x', 'y', 'z '};
// Second-level font offset
Int ioffset = 0;
/// Store the pronunciation of all second-level Chinese characters of the National Standard
Java. Lang. String ls_secondsectable =
"Csf-gnspgcgne [Y [btyyzdxykygt [jnnjqmbsgzscyjsyy" +
"[Pgkbzgy [ywjkgkljywkpjqhy [W [weight" +
"[Phffss [ybgxlppbyll [hlxs [ZM [jhsojnghdzqyklgjhsgqzhxqgkezzwyscjxyeyxadzpmssmzjzqjyzc [J" +
"[Pipeline [" +
"[Rule" +
"[Rule" +
"Using [ykldyxzpylgg [mtcfpajjzyljtyanjgbjplqgdzyqy" +
"Province" +
"Listen [nnlhlyyqyhwzptczgwwmzffjqqqqyxaclbhkdjxdgmmydjxzllsygx" +
"Gkjrywzwyclzmssjzldbyd [fcxyhlxchyzjq [[Listen [[ttxrycyxbyhcsmxjsznpwgpxx1_bgajcxly" +
"[Limit [PQ" +
"[Rule" +
"Lxgsssstclsldclrpbhzhxyyfhb [gdmycnqqwlqhjj [assets [htzkzjecxjcjnmfby [sfywybjzgnysdzsqyrslj" +
"Authorization [yzgwkypsgxfzfcdkhjgxdl1_sgdslqwzkxtmhsbgzmjzrglyj" +
"Province" +
"Province" +
"Pipeline [cjddyygywrhjrtgz" +
"Pipeline [dxx" +
"Lhjhf [sxzqhfzmzcztqcxzxrttdjhnnyzqqmnqdmmg [Unknown" +
"Kmkmpcklgdbqtfzswtfgglyplljzhgj [empty" +
"Pipeline [djlsly" +
"Pipeline [cn1_mpdjgklcljbctbjddbblczqrppxjcjlzcshltoljnmdddlngkaqhqh" +
"Jgykheznmshrp [Protocol" +
"Province" +
"Province" +
"Province" +
"Success ";
Java. Lang. String sreturn = "";
For (Int J = 0; j <A. Length (); j ++ ){
String stemp = A. substring (J, J + 1 );
Byte [] by = new byte [2];
By = stemp. getbytes ();
If (by. Length = 1 ){
Sreturn = sreturn + stemp;
} Else {
Int IA = 96 + (INT) by [0]; // area code
Int IB = 96 + (INT) by [1]; // bit code
Int in = Ia * 100 + IB;
If (in> 1600 & in <5590 ){
For (INT I = 0; I <24; I ++ ){
If (in <li_secposvalue ){
Sreturn = sreturn + lc_firstletter;
Break;
}
}
} Else {
Ioffset = (IA-56) * 94 + IB-1;
If (ioffset> = 0 & ioffset <= 3007 ){
Sreturn = sreturn +
Ls_secondsectable.substring (ioffset,
Ioffset + 1 );
}
}
}
Sreturn = sreturn. tolowercase ();
}
Return sreturn;
}
Public static void main (string [] ARGs ){
System. Out. println (New stringtools (). getpinym ("Chinese character "));
}
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.