有没有办法使用CsvHelper读取string[]形式的CSV数据?我想要类似的东西
csvReader reader = new Reader(dataFilePath);
string[] csvLine = reader.ReadLine();
或
List<string[]> allLines = reader.ReadAllLines();
例如如果文件看起来像这样:
Id,Name
1,one
我需要的结果是这样的:
List<string[]> allLines = new List<string[]>()
{ {"Id", "Name"}, {"1", "one"} };
GetRecords方法解析了我不想要的数据。
已更新当前
CsvHelper
,版本 30.0.1
void Main()
{
using (var reader = new StreamReader("path\\to\\file.csv"))
using (var csv = new CsvReader(reader, CultureInfo.InvariantCulture))
{
var allLines = new List<string[]>();
while (csv.Read())
{
allLines.Add(csv.Context.Reader.Parser.Record );
}
}
}