Padding zeros with FileHelpers
I am using FileHelpers to create NACHA files. Example below
Many of the properties are numeric with leading zeros, so they were defined as strings. Is there an attribute that can put leading zeros on the Class property, similar to how it FieldTrim/TrimMode
works to remove spaces?
[FixedLengthRecord()]
public class FileControlRecord
{
[FieldFixedLength(1)]
public int RecordTypeCode = 9; //Constant
[FieldFixedLength(6)]
public string BatchCount; //Numeric
[FieldFixedLength(6)]
public string BlockCount; //Numeric
[FieldFixedLength(8)]
public string EntryAddendaCount; //Numeric
[FieldFixedLength(10)]
public string EntryHash; //Numeric
[FieldFixedLength(12)]
public string TotalDebit; //$$$$$$$$$$cc
[FieldFixedLength(12)]
public string TotalCredit; //$$$$$$$$$$cc
[FieldFixedLength(39)]
[FieldNotInFile]
public string RESERVED; //Blank
}
+3
source to share
1 answer
You have to use FieldAlign with char padding:
[FixedLengthRecord()]
public class FileControlRecord
{
[FieldFixedLength(1)]
public int RecordTypeCode = 9; //Constant
[FieldFixedLength(6)]
public string BatchCount; //Numeric
[FieldFixedLength(6)]
public string BlockCount; //Numeric
[FieldFixedLength(8)]
public string EntryAddendaCount; //Numeric
[FieldFixedLength(10)]
public string EntryHash; //Numeric
[FieldFixedLength(12)]
[FieldAlign(AlignMode.Right, '$')]
public string TotalDebit; //$$$$$$$$$$cc
[FieldFixedLength(12)]
[FieldAlign(AlignMode.Right, '$')]
public string TotalCredit; //$$$$$$$$$$cc
[FieldFixedLength(39)]
public string RESERVED; //Blank
}
PS: I recommend that you use the latest version of the library:
https://github.com/MarcosMeli/FileHelpers/releases/latest
or via NuGet https://www.nuget.org/packages/FileHelpers/
+5
source to share