国标码中汉字的分布是有一定规律的,拼音首字母相同的汉字在同一区域(但多音字有例外),分布如下:
int[] gbCode = new int[] { 45217, 45253, 45761, 46318, 46826, 47010, 47297, 47614, 48119, -1, 49062, 49324, 49896, 50371, 50614, 50622, 50906, 51387, 51446, 52218, 52698, -1, -1, 52980, 53689,54481, 55290 };
在[gbCode[0],gbCode[1])区域是以a开关的汉字,.......
这样我们就可以先对需要查找的汉字字符串编码(用GB2312),然后判断即可。
private void init()
{
ArrayList<Integer> codeList;
for (String name : names)
{
codeList = new ArrayList<Integer>();
for (int k = 0; k < name.length(); k++)
{
codeList.add(getGBCode(name.charAt(k)));
}
gbCodeMap.put(name, codeList);
}
stack.push(gbCodeMap);
}
private int getGBCode(char word)
{
byte[] array = new byte[2];
int[] codes = new int[2];
try
{
array = String.valueOf(word).getBytes("GB2312");
for (int k = 0