Filehelpers fixed size records can it ignore a single extra space/line-ending in some files?

155 Views Asked by At

Using FileHelpers FixedFileEngine to read in large files from customers. One customer seems to have an extra whitespace per record (perhaps lf/cf TBD).

BUT can I support this difference easily in the parsing record definition?

[FixedLengthRecord()]
public class ClaimEntryDch
{
  ...
  [IgnoreOptionalWhitespace(1)] // something like this?
  string IgnoreThis { get; set; }
}
2

There are 2 best solutions below

1
Xerillio On

Perhaps you're looking for the [FieldOptional] attribute?

[FixedLengthRecord()]
public class ClaimEntryDch
{
    ...
    [FieldFixedLength(1)]
    [FieldOptional]
    string IgnoreThis { get; set; }
}

See this example fiddle for a demonstration.

0
kenny On

Answering my own Xerillo's answer pointed the way by creating an exception that gave me the eventual answer using FixedMode.AllowLessChars.

[FixedLengthRecord(FixedMode.AllowLessChars)]
public class ClaimEntryCenter