public bool bIsInt(string as_Number)
{
try
{
int iRet = Convert.ToInt32(as_Number);
}
catch(Exception e)
{
string s = e.ToString();
return false;
}
return true;
}
{
try
{
int iRet = Convert.ToInt32(as_Number);
}
catch(Exception e)
{
string s = e.ToString();
return false;
}
return true;
}
如果包含数字
foreach(char cha in yourstring)
{
if (cha>'0'&&cha<'9')
console.witeline("包含数字")
}
如果全部是数字
foreach(char cha in yourstring)
{
if (cha<'0'||cha>'9')
console.witeline("不全部是数字")
else
全部是数字
}
try
{
int.Parse(yourString);
}
catch()
{
MessageBox.Show("非数字字符串");
}
{
if(numstr.Length==0)
return false;
Regex reg = new Regex("^\\d+$");
if(reg.Match(numstr).Success)
return true;
else
return false;
}
orpublic static bool IsNumeric(string str) {
double resNum;
bool isNum = Double.TryParse(
str,System.Globalization.NumberStyles.Float,
System.Globalization.NumberFormatInfo.InvariantInfo,
out resNum
);
return isNum;
}