string pat = "你好么123"; string str = Regex.Replace(pat, @"[^\d.\d]", ""); int result = 0; if (Regex.IsMatch(str, @"^[+-]?\d*[.]?\d*$")) { result = Convert.ToInt32(str); }
//结果:result=123;
string pat = "你好么123"; string str = Regex.Replace(pat, @"[^\d.\d]", ""); int result = 0; if (Regex.IsMatch(str, @"^[+-]?\d*[.]?\d*$")) { result = Convert.ToInt32(str); }
//结果:result=123;
转载于:https://www.cnblogs.com/cang12138/p/5409393.html