FileHelpers
FileHelpers copied to clipboard
Support Fixed Length Attribute for defining the starting column in order to omit some uninteresting columns
It would be great if one could have the ability to ignore certain columns within a data file. I have the use case quite often, that there is much more data in it, than I need (and sometimes it is even difficult to figure out, which sort of data those columns represent!). So it would be great if I could make the definition based upon the start column in combination with the length or even an end column.
I will try to give an example:
017xcJuan Perez +004350011052002
005 Pedro Gomez -123423006022004
001abRamiro Politti -000000001022000
009klPablo Ramirez +033213024112002
^^^
ID ^^
not of interest
^^^^^^^^^^^^^^^^^^^^^
Name
^
not of interest
^^^^^^^^^^^^^^^
phone number
So the resulting definition would look like this:
using FileHelpers;
[FixedLengthRecord()]
public class Customer2
{
[FieldFixedLength(3)]
public int CustId;
// we would not need a field for the two column wide field
//[FieldFixedLength(2)]
//public string DontKnow;
[FieldFixedLength(20, 6)] // <- 6 = Start column
[FieldTrim(TrimMode.Right)]
public string Name;
// we would not need a field for the "+ / - " column
//[FieldFixedLength(1)]
//public string DontKnowEither;
[FieldFixedLength(16)]
[FieldStartColumn(27)] // or explicitly like this?
public string Phone;
}
This would be a huge improvement!
Just use the FieldHidden attribute, look https://www.filehelpers.net/mustread/