Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/typo3/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
访问1000多个数字的最佳方式C#_C#_Datagridview_Datatable_Numbers_Zedgraph - Fatal编程技术网

访问1000多个数字的最佳方式C#

访问1000多个数字的最佳方式C#,c#,datagridview,datatable,numbers,zedgraph,C#,Datagridview,Datatable,Numbers,Zedgraph,所以问题是: 我有一个带有*.sld extesnion的文件。 该文件包含大约94列和24500行数字,可以作为普通文本文件读取。 从程序中访问这些数字的最佳方式是什么?例如,我希望第15列中的所有数字都存储为double。我有什么选择? 我尝试过DATABATE,但是用Fiel.RealLoad加载整个文件需要大约50MB的RAM内存来运行这个程序,我必须考虑这个程序将使用不止一个这样的文件。 *.sld文件的片段如下所示: 0.000 96.47 2.51 1.43

所以问题是: 我有一个带有*.sld extesnion的文件。 该文件包含大约94列和24500行数字,可以作为普通文本文件读取。 从程序中访问这些数字的最佳方式是什么?例如,我希望第15列中的所有数字都存储为double。我有什么选择? 我尝试过DATABATE,但是用Fiel.RealLoad加载整个文件需要大约50MB的RAM内存来运行这个程序,我必须考虑这个程序将使用不止一个这样的文件。 *.sld文件的片段如下所示:

0.000    96.47     2.51     1.43     2.56     2.47     5.83 -> more columns
1.030    96.47     2.52     1.39     3.14     2.43     5.60  |
2.044    96.47     2.43     1.63     2.96     2.34     5.86  \/
3.058    96.47     2.47     0.76     2.59     2.44     5.62  more rows
4.072    96.47     2.56     1.39     2.99     2.38     5.89
//Read all lines of opened file to string array
string[] lines = System.IO.File.ReadAllLines(@OFD.FileName,Encoding.Default);
//Remove more than one whitespace with only one whitespace in cycle (cycle not shown)
string partialLine = Regex.Replace(lines[i], @"\s+", " ");
//Split string to string array and add it to dataTable
string[] partialLineElement = partialLine.Split(new char[]{' '}, StringSplitOptions.RemoveEmptyEntries);
fileData.Rows.Add(partialLineElement);
除了前面提到的更多列和行之外。 我的解决方案是这样的:

0.000    96.47     2.51     1.43     2.56     2.47     5.83 -> more columns
1.030    96.47     2.52     1.39     3.14     2.43     5.60  |
2.044    96.47     2.43     1.63     2.96     2.34     5.86  \/
3.058    96.47     2.47     0.76     2.59     2.44     5.62  more rows
4.072    96.47     2.56     1.39     2.99     2.38     5.89
//Read all lines of opened file to string array
string[] lines = System.IO.File.ReadAllLines(@OFD.FileName,Encoding.Default);
//Remove more than one whitespace with only one whitespace in cycle (cycle not shown)
string partialLine = Regex.Replace(lines[i], @"\s+", " ");
//Split string to string array and add it to dataTable
string[] partialLineElement = partialLine.Split(new char[]{' '}, StringSplitOptions.RemoveEmptyEntries);
fileData.Rows.Add(partialLineElement);
但我在访问整列数据时遇到问题,它是一个字符串数组,而不是双精度数字。我需要它将此文件的一列作为double[]添加到ZedGraph。我还尝试将此dataTable分配给dataGridView,如下所示:

dataGridView1.DataSource = fileData;
dataGridView1.Refresh();
但是如何以双[]的形式访问列??? 有什么建议吗

但是如何以双[]的形式访问列???有什么建议吗

您可以使用不将整个文件加载到memmory中的

ReadLines和ReadAllLines方法的区别如下:使用ReadLines时,可以在返回整个集合之前开始枚举字符串集合;使用ReadAllLines时,必须等待返回整个字符串数组,然后才能访问该数组。因此,当您处理非常大的文件时,ReadLines会更加高效

获取所有列


在过去,我使用StreamReader从一个示例文件中导入了大约30000行,将每行解析为30个不同的单元格,并将其导入数据库。读取和解析只需几秒钟。你可以试一试。只需确保在“using”语句中使用它


至于解析第15列,我想不出比编写函数更好的方法。

您如何使用这些数据?这将决定是否需要将整个文件的数据放入内存。例如,如果一次只能读取一行,则可以显著减少内存占用。所有列都是双值,还是不同的列具有不同的类型?下面是一篇关于使用正则表达式从日志文件中“挑选”一些值的好文章。但是,由于您的文件大小,它可能会很慢。。。。。。。。您应该考虑解析文件(一天一次),并将解析结果保存在某处……并将数据绑定到解析结果。