string strVal="58015 116.33 34.42 43 2 360 1 9
";
strVal=Regex.Replace(strVal,@"\s+"," ");
string strVal[]=strVal.Split(' ');
再把数组里的每个数字转为float类型!
";
strVal=Regex.Replace(strVal,@"\s+"," ");
string strVal[]=strVal.Split(' ');
再把数组里的每个数字转为float类型!
下面是代码片断
string yourStr = @"58015 116.33 34.42 43 2 360 1 9 -1 1 360 1
58016 116.97 34.18 35 2 360 1 9 -1 1 360 1
58102 115.77 33.87 38 2 360 1 9 -1 1 360 1
58107 115.25 33.07 36 2 360 1 10 0 1 360 1
58108 115.37 33.27 38 2 360 1 10 0 1 360 1
58109 115.62 33.18 33 2 360 1 10 0 1 360 1
58114 116.20 33.50 31 2 360 1 10 0 1 360 1
58116 116.82 33.98 34 2 360 1 9 -1 1 360 1
58117 116.22 33.15 28 2 360 1 10 0 1 360 1
58118 116.55 33.28 27 2 360 1 10 0 1 360 1
";
string regexStr = @"[-+]?\b(?:[0-9]*\.)?[0-9]+\b";
MatchCollection mc = Regex.Matches(yourStr, regexStr);
foreach(Match m in mc)
{
Console.WriteLine(m.Value);
}这个一次把所有的数字都读出来了,如果只需要一行,有两种办法:1.yourStr中每次只放一行的数据;2.将foreach改为for。
比如mc[i].Value,就是一个字符串。