posts - 2,comments - 0,trackbacks - 0

正则表达的写法是:

static   bool  IsNumeric( string  str) 
{  
   System.Text.RegularExpressions.Regex reg1 
       =   new  System.Text.RegularExpressions.Regex( @" ^[-]?\d+[.]?\d*$ " );  
  
return  reg1.IsMatch(str); 
}
 

其实用正则表达式也可以
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;
  }
posted on 2006-10-10 09:32 牛排 阅读(87) 评论(0)  编辑 收藏 引用 所属分类: 学习心得
只有注册用户登录后才能发表评论。