我有一个如下所示的dat文件:
我希望将此数据转换为某种类型的矩阵,其中包含空格的值。知道如何处理这个问题吗?
答案 0 :(得分:0)
如果您希望保留空白区域,则可能需要将数据视为固定宽度列。
https://codereview.stackexchange.com/questions/27782/how-to-read-fixed-width-data-fields-in-net
如果事实证明数据是以@WaiHaLee建议的制表符分隔的,那么只需使用制表符分割这些行。例如:
//read all lines
var lines = System.IO.File.ReadAllLines("C:/path/to/file.txt");
//loop through all lines
foreach(var line in lines)
{
//split the line
var splitString = line.Split(new char[] { '\t' });
//pull out some data from the 6th column
double avDP = double.Parse(splitString[5]);
//save the data wherever you want
}