C# 中 分割字符串,以及将字符串分割后的 字符串数组 进行数字验证的操作
作者:互联网
var values = new List<double>(); var str = "1\r\n2,3,-0.01,-00.02,-.3,001,adfa\r\n"; var vals = str.Split(new string[] { "\r\n",",","|","\r","\n" }, StringSplitOptions.None);//按照一定条件分割 foreach (var val in vals) { var isNum = Regex.IsMatch(val, @"^-?\d+$|^(-?\d+)(\.\d+)?$");//正则检查是否是数字(可正负,可小数) if (isNum) { double.TryParse(val, out double value); values.Add(value); } }
标签:分割,val,C#,isNum,var,字符串,new,vals 来源: https://www.cnblogs.com/5MBPerSec/p/12533897.html