如何跳过csv文件中的标题行?

时间:2011-05-03 08:29:34

标签: vb.net csv

我有第一行标题生成的csv文件和其余的数据。该文件每次都有所不同,我必须拥有所有这些值以供进一步使用。我正在使用File.ReadAllLines(路径),但可以忽略标题行。怎么做到这一点?请帮忙。

2 个答案:

答案 0 :(得分:1)

你应该从第二行(index 1 of returned string[]

开始

答案 1 :(得分:1)

编辑这样更好:

File.ReadAllLines(@"c:\test.txt").Skip(1); // this will return an IEnumerable<string>
File.ReadAllLines(@"c:\test.txt").Skip(1).ToArray(); // This will return an array of string (string[])

<强> OLD

bool first = true;
StringBuilder sb = new StringBuilder();
    File.ReadLines(@"c:\test.txt").ToList().ForEach(c => 
    { 
        if (first) first = false;
        else sb.Append(c); 
    }
    );

string res = sb.ToString();

这将意外地跳过第一行,不知道是否有更好的方法来做到这一点

相关问题