一通用函数,可以判断字符串是否是数值类型:
private bool IsNumberic(string str)
{
if (str == null || str.Length == 0)
return false;
System.Text.ASCIIEncoding ascii = new System.Text.ASCIIEncoding();
byte[] bytestr = ascii.GetBytes(str);
foreach(byte c in bytestr)
{
if (c < 48 || c > 57)
{
return false;
}
}
return true;
}
本文介绍了一个简单实用的方法来判断一个字符串是否只包含数值字符。通过使用ASCII编码转换,该方法遍历字符串中的每个字符并检查其是否位于'0'和'9'的ASCII值范围内。
2622

被折叠的 条评论
为什么被折叠?



