C# 字符串提取数值(带小数点)

C# 字符串提取数值(带小数点)
这里写图片描述

string input = "树2草45210.2m2";
if (GetInputUtil.GetString("\n请输入带数值的字符串:", input, out input))
{
    Regex r = new Regex(@"\d*\.\d*|0\.\d*[1-9]\d*$");

    string[] result = new string[] { r.Match(input).Value, r.Replace(input, "") };

    for (int i = 0; i < result.Length; i++)
    {
        ed.WriteMessage(string.Format("\n{0} = {1}", i, result[i]));
    }
    ed.WriteMessage("\n---------------------------");

    // 0 = 45210.2
    // 1 = 树2草m2
}

猜你喜欢

转载自blog.csdn.net/csdn_wuwt/article/details/80282271
今日推荐