Ignore NewLIne inside a field in FileHelpers C#

Viewed 1166

I am fairly new using FileHelpers Class for parsing the CSV. I have a file like this...

    "background","Info","Agent abcdefg
    ===================
    Context Tenant: {Vendor: 1, Customer: 719046046}","2,140.69","","7/11/2017 3:30 AM"

I would like to ignore any newline and would like to read that as one string. Can you please help?

so at the end of the line it is \r\n and i want this to be removed.

2 Answers

[FieldQuoted(QuoteMode.OptionalForBoth, MultiLineMode.AllowForBoth)] and [FieldQuoted()] didn't work for my case.

What I end up doing is reading the file using File.ReadAllText, replacing \r\n with an empty value and then feeding the read string to FileHelperEngine``ReadString.

In my case the csv was generated with \n line endings and human comments were added using \r\n

  var engine = new FileHelperEngine<LLU>();

  var fileText = File.ReadAllText("myfile.csv");
  fileText = Regex.Replace(fileText, @"\r\n", ""); // Remove lines added by humans in comments

  var result = engine.ReadString(fileText)
Related