JAVA取汉字拼音类

public class StringTools {
public StringTools() {
}
//取得拼音码
public String getPinYM(String a) {
//汉字区位码
int li_SecPosValue[] = {1601, 1637, 1833, 2078, 2274, 2302, 2433, 2594,
2787, 3106, 3212, 3472, 3635, 3722, 3730, 3858,
4027, 4086, 4390, 4558, 4684, 4925, 5249, 5590};
//存放国标一级汉字不同读音的起始区位码对应读音
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'};
//二级字库偏移量
int ioffset = 0;
////存放所有国标二级汉字读音
java.lang.String ls_SecondSecTable =
"CJWGNSPGCGNE[Y[BTYYZDXYKYGT[JNNJQMBSGZSCYJSYY" +
"[PGKBZGY[YWJKGKLJYWKPJQHY[W[DZLSGMRYPYWWCCKZNKYYGTTNJJNYKKZYTCJNMCYLQLYPYQFQRPZSLWBTGKJFYXJWZLTBNCXJJJJTXDTTSQZYCDXXHGCK" +
"[PHFFSS[YBGXLPPBYLL[HLXS[ZM[JHSOJNGHDZQYKLGJHSGQZHXQGKEZZWYSCSCJXYEYXADZPMDSSMZJZQJYZC[J" +
"[WQJBYZPXGZNZCPWHKXHQKMWFBPBYDTJZZKQHYLYGXFPTYJYYZPSZLFCHMQSHGMXXSXJ[" +
"[DCSBBQBEFSJYHXWGZKPYLQBGLDLCCTNMAYDDKSSNGYCSGXLYZAYBNPTSDKDYLHGYMYLCXPY" +
"[JNDQJWXQXFYYFJLEJPZRXCCQWQQSBNKYMGPLBMJRQCFLNYMYQMSQYRBCJTHZTQFRXQHXMJJCJLXQGJMSHZKBSWYEMYLTXFSYDSWLYCJQXSJNQBSCTYHBFTDCYZDJWY" +
"GHQFRXWCKQKXEBPTLPXJZSRMEBWHJLBJSLYYSMDXLCLQKXLHXJRZJMFQHXHWYWSBHTRXXGLHQHFNM[YKLDYXZPYLGG[MTCFPAJJZYLJTYANJGBJPLQGDZYQY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GDZDBLZYYCXNNCSYBZBFGLZZXSWMSCCMQNJQSBDQSJTXXMBLTXZCLZSHZCXRQ" +
"JGJYLXZFJPHYMZQQYDFQJJLZZNZJCDGZYGCTXMZYSCTLKPHTXHTLBJXJLXSCDQXCBBTJFQZFSLTJBTKQBXXJJLJCHCZDBZJDCZJDCPRNPQCJPFCZLCLZXZDMXMPH" +
"JSGZGSZZQLYLWTJPFSYASMCJBTZKYCWMYTCSJJLJCQLWZMALBXYFBPNLSFHTGJWEJJXXGLLJSTGSHJQLZFKCGNNNSZFDEQFHBSAQTGYLBXMMYGSZLDYDQMJJRGBJ" +
"TKGDHGKBLQKBDMBYLXWCXYTTYBKMRTJZXQJBHLMHMJJZMQASLDCYXYQDLQCAFYWYXQHZ";
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]; //区码
int ib = 96 + (int) by[1]; //位码
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( "汉字" ));
}
}

你可能感兴趣的:(java,C++,c,C#,J#)