c#判断字符串是否是数字

public static bool IsNumeric(string str)
        {
            bool bResult = true;
            foreach (char chr in str)
            {
                if (chr < '0' || chr > '9')
                {
                    bResult = false;
                    break;
                }
            }
            return bResult;
        }

正则表达式:

public static bool IsNumeric(string value)
{
         return Regex.IsMatch(value, @"^[+-]?/d*[.]?/d*$");
}
发布了31 篇原创文章 · 获赞 2 · 访问量 2551

猜你喜欢

转载自blog.csdn.net/fangyu723/article/details/103385915
今日推荐