regex to split line (csv file)

后端 未结 7 1794
予麋鹿
予麋鹿 2020-12-03 12:37

I am not good in regex. Can some one help me out to write regex for me?

I may have values like this while reading csv file.

\"Artist,Name\",Album,12-SCS
\         


        
相关标签:
7条回答
  • 2020-12-03 13:19

    It could be done using below code:

    using Microsoft.VisualBasic.FileIO;
    string csv = "1,2,3,"4,3","a,"b",c",end";
    TextFieldParser parser = new TextFieldParser(new StringReader(csv));
    //To read from file
    //TextFieldParser parser = new TextFieldParser("csvfile.csv");
    parser.HasFieldsEnclosedInQuotes = true;
    parser.SetDelimiters(",");
    string[] fields =null;
    while (!parser.EndOfData)
    {
        fields = parser.ReadFields();
    }
    parser.Close();
    
    0 讨论(0)
提交回复
热议问题