CSV Parsing

前端 未结 13 2154
攒了一身酷
攒了一身酷 2020-12-17 04:45

I am trying to use C# to parse CSV. I used regular expressions to find \",\" and read string if my header counts were equal to my match count.

Now this

13条回答
  •  感动是毒
    2020-12-17 05:43

    FileHelpers supports multiline fields.

    You could parse files like these:

    a,"line 1
    line 2
    line 3"
    b,"line 1
    line 2
    line 3"
    

    Here is the datatype declaration:

    [DelimitedRecord(",")]
    public class MyRecord
    { 
     public string field1;
     [FieldQuoted('"', QuoteMode.OptionalForRead, MultilineMode.AllowForRead)]
     public string field2;
    }
    

    Here is the usage:

    static void Main()
    {
     FileHelperEngine engine = new FileHelperEngine(typeof(MyRecord));
     MyRecord[] res = engine.ReadFile("file.csv");       
    }
    

提交回复
热议问题