I use FileHelpers to import data from a CSV file. The problem is that some versions of the CSV file have more fields than others.
As such, I marked fields that are sometimes missing as optional, but this doesn't seem to work, instead of just ignoring when fields are missing (which seems to be all right), it also always breaks the last character from the last present fields.
For instance...
- a string containing "ABC, DEF, GHI" (without quotes) imports as "ABC", "DEF" and "GHI"
- a string containing "ABC, DEF" (again without quotes) imports both "ABC" and "DE"
My recording format is defined as follows:
[DelimitedRecord(@",")] public class RecordFormat { [FieldTrim(TrimMode.Both)] public String FirstValue; [FieldTrim(TrimMode.Both)] public String SecondValue; [FieldOptional] [FieldTrim(TrimMode.Both)] public String OptionalValue; }
Can anyone say what I am missing?
Thanks.
source share