C# 获取字符串中的数字

            string s = "-112315-125-56()5555";

第一种方法
            MatchCollection results = Regex.Matches(s, @"[0-9]+", RegexOptions.IgnoreCase | RegexOptions.Multiline);
            string str = "";
            for (int i = 0; i < results.Count; i++)
            {
                str += results[i].Value.ToString();
            }

第二种方法

            Match result = Regex.Match(s, @"[0-9]+", RegexOptions.IgnoreCase | RegexOptions.Multiline);

            while (result.Success)
            {
                str += result.Value;
                result = result.NextMatch();
            }

原文地址:https://www.cnblogs.com/swarb/p/9924433.html