Java全角字符转换为半角字符的实现方法
2009-04-23 20:54:31 来源:WEB开发网核心提示: /**java全角字符转换为半角字符的实现方法*/ /** * 输入的全角转为半角<br> * * @return */ PRivate String quanToban(String message) { String outStr = ""; String Tstr =
/**java全角字符转换为半角字符的实现方法*/
/**
* 输入的全角转为半角<br>
*
* @return
*/
PRivate String quanToban(String message) {
String outStr = "";
String Tstr = "";
byte[] b = null;
for (int i = 0; i < message.length(); i++) {
try {
Tstr = message.substring(i, i + 1);
b = Tstr.getBytes("unicode");
} catch (java.io.UnsupportedEncodingException e) {
e.printStackTrace();
}
if (b[3] == -1) {
b[2] = (byte) (b[2] + 32);
b[3] = 0;
try {
outStr = outStr + new String(b, "unicode");
} catch (java.io.UnsupportedEncodingException e) {
e.printStackTrace();
}
} else {
outStr = outStr + Tstr;
}
}
return outStr;
}
更多精彩
赞助商链接