public static bool IsNumber (this string str)
{
return new Regex(@"\b\-?\d+(?:\.\d+)?\b|\b\.\d+\b").IsMatch(str);
}
Usage
"5.5".IsNumber() // true
"five".IsNumber // false
本文介绍了一个使用正则表达式判断字符串是否表示数字的方法,包括基本概念、实现代码及示例使用。
public static bool IsNumber (this string str)
{
return new Regex(@"\b\-?\d+(?:\.\d+)?\b|\b\.\d+\b").IsMatch(str);
}
"5.5".IsNumber() // true
"five".IsNumber // false

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