尝试读取一个文件,该文件的数据不是用逗号,
隔开,而是使用引号:"
例如:
"num" "date" "callsite" "level" "thread"
可以做到吗?
csvhelper
给出了一个例外,即找不到标头。
答案 0 :(得分:1)
如果数据由制表符分隔,则可以设置csv.Configuration.Delimiter = "\t";
public class Program
{
public static void Main(string[] args)
{
using (MemoryStream stream = new MemoryStream())
using (StreamWriter writer = new StreamWriter(stream))
using (StreamReader reader = new StreamReader(stream))
using (CsvReader csv = new CsvReader(reader))
{
writer.WriteLine("\"num\"\t\"date\"\t\"callsite\"\t\"level\"\t\"thread\"");
writer.WriteLine("\"1\"\t\"1/1/2019\"\t\"callsite1\"\t\"high\"\t\"20\"");
writer.Flush();
stream.Position = 0;
csv.Configuration.Delimiter = "\t";
var results = csv.GetRecords<Foo>().ToList();
}
Console.ReadKey();
}
}
public class Foo
{
public int num { get; set; }
public DateTime date { get; set; }
public string callsite { get; set; }
public string level { get; set; }
public string thread { get; set; }
}