static bool IsNumeric(string str) 
...{
if (str==null || str.Length==0)
return false;
foreach(char c in str) 
...{
if (!Char.IsNumber(c)) 
...{
return false;
}
}
return true;
} 正则表达的写法是:
static bool IsNumeric(string str) 
...{
System.Text.RegularExpressions.Regex reg1
= new System.Text.RegularExpressions.Regex(@"^[-]?d+[.]?d*$");
return reg1.IsMatch(str);
}

本文介绍了两种实现字符串数值验证的方法:一种是通过逐字符检查的方式判断字符串是否全为数字;另一种则是利用正则表达式来判断字符串是否符合数字的格式,包括整数、小数及负数。
212

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



