C#怎么读取txt里面的数据进行计算呢?虚心求教!
这个是txt里面的数据格式,数据比较多,为坐标数据,x和y,现在想对x和y进行计算,一行一行的计算,然后输出txt的文件,该怎么做呢?特别是里面的1和end怎么处理?有没有朋友有例子可以供参考?
1
169.868592016381,-73.2891742320069
169.388181055691,-73.5364222712322
169.750305089806,-73.6008442380541
169.918029151954,-73.5541793331424
169.868592016381,-73.2891742320069
END
2
166.631652045891,-77.1728092143666
166.372218060531,-77.2768852946332
166.61984412359,-77.3842371903049
166.217103062991,-77.5354373361399
166.858577993192,-77.6655682271997
166.557771101318,-77.7088312528823
166.873689055903,-77.7293783150887
166.776642039652,-77.8577902454421
167.583618151274,-77.6366872062885
168.940557082799,-77.6402872337091
169.423001996118,-77.4629782976242
167.379696002005,-77.3836162589165
166.631652045891,-77.1728092143666
END
------解决方案--------------------先搞清楚怎么读,StreamReader可以一行行读,然后用string的split根据逗号分割,将你要的数据组织到内存,数组也好,list也好,datatable也好,读完了,组织完了,剩下自己就算吧
------解决方案--------------------StreamReader reader = new StreamReader(@"路径");
while (!reader.EndOfStream)
{
string line = reader.ReadLine();
string[] values = line.Split(',');
if (values.Length == 2)
//values[0]为x值,values[1]为y值
}
reader.Close();
------解决方案--------------------读取所有行
File.ReadAllLines 方法 (String, Encoding)