2011-05-03 62 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

相關問題