青春有我
我最喜欢的CSV解析器是一个内置在.NET库中的解析器。这是Microsoft.VisualBasic命名空间中隐藏的宝藏。下面是一个示例代码:using Microsoft.VisualBasic.FileIO;var path = @"C:\Person.csv";
// Habeeb, "Dubai Media City, Dubai"using (TextFieldParser csvParser = new TextFieldParser(path)){
csvParser.CommentTokens = new string[] { "#" };
csvParser.SetDelimiters(new string[] { "," });
csvParser.HasFieldsEnclosedInQuotes = true;
// Skip the row with the column names
csvParser.ReadLine();
while (!csvParser.EndOfData)
{
// Read current line fields, pointer moves to the next line.
string[] fields = csvParser.ReadFields();
string Name = fields[0];
string Address = fields[1];
}}记住要添加引用Microsoft.VisualBasic有关解析器的更多细节在这里给出:http:/cotopaters.blogpot.ae/2015/11/c-最简单的-CSV-解析器-内置net.html