Search code examples
c#filehelpers

What's the cleanest way to get record as string in FileHelpers?


When I'm parsing a text file, and importing it in my application through the (truly wonderful) FileHelpers library, for each error that occurs I want to log in a separate text file the record that failed (along with the error of course), like

Error: The record ..... failed with error ....

This brings the question in the title: I see there's the method WriteString(IEnumerable<T>), but if I call

string recordAsString = engine.WriteString(new List<T>() { record });

the result string contains a new line in it, and the only way I managed to "clean" it is

recordAsString = recordAsString.Substring(0, recordAsString.Length - 2);

Is there a cleaner way, ie a method that returns the record as a string that doesn't contain any new line?

Thank you


Solution

  • You can try with

    var recordAsString = engine.Options.RecordToString(record);
    

    Thanks for using the library