11

I have a csv file with two lines, the first one is the header line, which includes 36 columns separated by ,

The second line is the values, which are 36 value separated by ,

I want to read the second line, I found that all people talk about csvHelper package, so I download it, but it doesn't have any dll to add to my project.

my question is how to include it and how to read the second line.

を使用してインストールできることはわかっていInstall-Package CsvHelperますが、このアプリケーションをサーバーにデプロイしたいので、そのようにしたくありません。したがって、何か方法があればいいのですがadd reference

含める方法を知っていれば、2行目を読むのは難しくありません. 私はこのようなことをします:

  1. csv ファイルを読み込む
  2. 最初の行を読んで無視します。
  3. 2 行目を読み、 で分割し,ます。
4

2 に答える 2

21

TextReader.ReadLine()最初の行をスキップするために使用できます:

using (TextReader reader = File.OpenText("filename"))
{
    reader.ReadLine();
    // now initialize the CsvReader
    var parser = new CsvReader( reader ); // ...
}
于 2014-07-29T11:26:20.857 に答える