gpt4 book ai didi

c# - 使用 FileHelpers 填充零

转载 作者:行者123 更新时间:2023-11-30 14:27:45 24 4
gpt4 key购买 nike

我正在使用 FileHelpers 创建 NACHA 文件。下面的例子

许多属性都是带有前导零的数字,因此它们被定义为字符串。是否有一个属性可以填充 Class 属性中的前导零,类似于 FieldTrim/TrimMode 用于删除空格的方式?

[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
}

最佳答案

您必须将 FieldAlign 与填充字符一起使用:

[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:我建议你使用最新版本的库:

https://github.com/MarcosMeli/FileHelpers/releases/latest

或通过 NuGet https://www.nuget.org/packages/FileHelpers/

关于c# - 使用 FileHelpers 填充零,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31749811/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com