Search code examples
c#csvhelper

CSV HELPER Setting the max number of split to 3


I am mapping the contents of a 3 column CSV file to an object, but I am not sure of the contents of the last column because it can contain my delimiter. So, I would like to map by setting the number of split to 3:

public MyDataAutoMapper()
{      
    Map(m => m.Id).NameIndex(0);
    Map(m => m.IdDaTa).Index(1);
    Map(m => m.xmlData).Index(2);
}

Solution

  • I dropped CSV HELPER, and I have used a simple split that ignores the contents of the last column

    char[] Delimiters = new char[] { ',' };

    var splitedString = line.Split(Delimiters, 3);