工具代码总结
作者:
风语安然 | 来源:发表于
2015-03-21 18:37 被阅读37次 //单个汉字转成ansi
public static int getChsAscii(String chs){
int asc=0;
try {
byte[] bytes=chs.getBytes("gb2312");
if(bytes==null||bytes.length==0){
throw new RuntimeException("illegal resource string");
}
if(bytes.length==1){ //英文字符
asc=bytes[0];
}
if(bytes.length==2){ //中文字符
int highByte=256+bytes[0];
int lowByte=256+bytes[1];
asc=(256*highByte+lowByte)-256*256;
}
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return asc;
}
本文标题:工具代码总结
本文链接:https://www.haomeiwen.com/subject/zoowxttx.html
网友评论