/// <summary>
/// 字符串中获取数字()
/// </summary>
/// <param name="str"></param>
/// <returns></returns>
public static decimal GetNumberInStr(string str)
{
decimal result = 0;
if (str != null && str != string.Empty)
{
string Opt = str;
Opt = System.Text.RegularExpressions.Regex.Replace(Opt,@"[^\d.\d]","");// 获取其中的小数部分,如果斜杠反过来,则不成立
if (!string.IsNullOrEmpty(Opt))///如果不为空则为小数
{
if (System.Text.RegularExpressions.Regex.IsMatch(Opt, @"^[+-]?\d*[.]?\d*$"))
{
result = decimal.Parse(Opt);
}
}
}
return result;
}
在字符串中获取到数字以及带小数点的数字
最新推荐文章于 2023-09-23 09:55:52 发布