c bool IsNumeric(string str) //接收一個string類型的參數,保存到str里
{
if (str == null || str.Length == 0) //驗證這個參數是否為空
return false; //是,就返回False
ASCIIEncoding ascii = new ASCIIEncoding();//new ASCIIEncoding 的實例
byte[] bytestr = ascii.GetBytes(str); //把string類型的參數保存到數組里
foreach (byte c in bytestr) //遍歷這個數組里的內容
{
if (c < 48 || c > 57) //判斷是否為數字
{
return false; //不是,就返回False
}
}
return true; //是,就返回True
}
//備注 數字,字母的ASCII碼對照表
/*
0~9數字對應十進制48-57
a~z字母對應的十進制97-122十六進制61-7A
A~Z字母對應的十進制65-90十六進制41-5A
*/
