FileHelpers icon indicating copy to clipboard operation
FileHelpers copied to clipboard

Support Padding via a Converted in the library

Open iremmats opened this issue 10 years ago • 6 comments

Support padding without having to write your own converter. http://stackoverflow.com/questions/22015002/filehelpers-mixing-delimited-and-fixed-length-records

iremmats avatar Aug 11 '15 19:08 iremmats

Hi @iremmats

Padding is already supported, but not well documented :-1:

You must use FieldAlign, http://www.filehelpers.net/docs/html/T_FileHelpers_FieldAlignAttribute.htm

Can you translate the answer to stackoverflow ? thanks !!

[DelimitedRecord("|")]
public class Customer
{
    public int CustId; //variable length

    public string Name; //variable length

    public decimal Balance; //variable length

    [FieldConverter(ConverterKind.Date, "dd-MM-yyyy")]
    public DateTime AddedDate;

    [FieldAlign(AlignMode.Right, '0')]
    public int Code; // this one must have 10 characters with "zero-fill", like
         // 153 must look like 0000000153
}

MarcosMeli avatar Aug 11 '15 19:08 MarcosMeli

After hit comment I understand that is for a DelimitedRecord :cry:

Is implemented for FixedLengthRecord classes, so is a feature to consider

MarcosMeli avatar Aug 11 '15 19:08 MarcosMeli

My use cases has been with fixed field records so far. But yeah, it would be a nice feature for Delimited Records too.

iremmats avatar Aug 11 '15 19:08 iremmats

We must add a

 PaddingConverter(totalLength, paddingChar)

or something like

MarcosMeli avatar Aug 11 '15 20:08 MarcosMeli

Make sure it support both left and right padding plus there is no problem with int/string/decimal conversions. Most cases its numbers that needs zeros using left padding.

iremmats avatar Aug 11 '15 20:08 iremmats

You are right

[PaddingConverter(totalLength, alignMode, paddingChar)

MarcosMeli avatar Aug 11 '15 20:08 MarcosMeli