?? characode.java
字號:
package ECDictionaryUtil;
public class CharaCode {
/**
* @param args
*/
public int getCharaCode(String chara)throws Exception
{ byte[] bytes = chara.getBytes("gbk");
if(bytes == null || bytes.length > 2 || bytes.length <= 0|| bytes.length == 1)
{ throw new Exception("不是一個有效的漢字!"); }
if(bytes.length == 2){ //漢字
int hByte,lByte;//漢字的高字節和低字節
if (bytes[0]<0)
{
hByte = 256 + bytes[0];
}
else{
//hByte = bytes[0];
throw new Exception("不是一個有效的漢字!");
}
if (bytes[1]<0)
{
lByte= 256 + bytes[1];
}
else{
//lByte = bytes[1];
throw new Exception("不是一個有效的漢字!");
}
int iHanzi = (256 * hByte + lByte);
return iHanzi;
}
throw new Exception("不是一個有效的漢字!");
}
public static void main(String[] args) {
String cha="華";
try{
System.out.println(new CharaCode().getCharaCode(cha));
}catch(Exception ee){
System.out.println(ee.getMessage());
}
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -