2011-05-03 63 views
-2

我有一个csv文件,其中包含第一行的标题和其余的数据。该文件每次都有所不同,我必须具备所有这些值供进一步使用。我正在使用File.ReadAllLines(路径),但可以忽略标题行。如何做到这一点?请帮忙。如何跳过csv文件中的标题行?

回答

1

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

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); 
    } 
    ); 

串解析度= sb.ToString( );

这将essentually跳过第一行,不知道是否有更好的方式来做到这一点

+0

错误:“跳过”不是的System.Array的memebr。我需要将这些值用于进一步的迭代。有没有其他方法可以跳过这条线? – Anudeep 2011-05-03 08:42:02

+0

添加一个using:using System.Linq; – 2011-05-03 08:50:31

相关问题