本帖最後由 pizg 於 2011-9-29 23:18 編輯
我寫了一個很笨的函數, 將ASCII碼轉成字元, 如下:
String toChr(int n)
{
String s = "";
switch (n)
{
case 44:
s = ",";
break;
case 46:
s = ".";
break;
case 49:
s = "1";
break;
case 50:
s = "2";
break;
....
case 65:
s = "A";
break;
case 66:
s = "B";
break;
case 67:
s = "C";
break;
....
}
return s;
}
應該有更簡便的方法吧, 例如用查表法:
String toChr(int n)
{
String s = "";
String strTable = ",.12345678ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
s= strTable.substring(n , 1);
return s;
}
請問此程式要如何修改使之正確呢? |