求教中文字符全角转半角问题
方法如下,是在论坛里看某位兄弟的方法,我在使用的时候发现转换某些中文的时候出现乱码,请各位大哥指点指点
例如: 0#a5465757oct342342042#13973119452#20051130201232#051212#保健一第一第一#省第一外科#主任#省第一1216#省第一上午
输出后变成:0#a5465757oct342342042#13973119452#20051130201232#051212#?∫坏谝坏谝?省第一外科#主任#省第一1216#省第一上午
public static String getBjChnValue(String key) {
byte[] temp = key.getBytes();
int len = temp.length;
int qjlen = 0;
for (int m = 0; m < len; m++) { //计算全角字母的个数
if (temp[m] == -93) {
qjlen++;
m++;
}
}
byte[] ret = new byte[len - qjlen];
for (int i = 0, j = 0; j < len; i++, j++) {
if (temp[j] == -93) { //全角的
temp[j + 1] += 128;
ret[i] = temp[j + 1];
j++;
} else {
ret[i] = temp[j]; //普通的
}
}
String retString = new String(ret);
return retString;
}