MarcosMeli / FileHelpers

The FileHelpers are a free and easy to use .NET library to read/write data from fixed length or delimited records in files, strings or streams
https://www.filehelpers.net
MIT License
1.13k stars 349 forks source link

Fixed Length Field ignores TrimChars from FieldTrimAttribute #281

Open kevinmbrooks opened 6 years ago

kevinmbrooks commented 6 years ago

Using the FieldTrimAttribute with the FieldFixedLengthAttribute trims whitespace correctly, but when you specify trim characters in the FieldTrimAttribute constructor, they are ignored and whitespace is still trimmed. A brief look at the code suggests to me that delimited fields are handling trim characters correctly, but fixed length fields are ignoring them.

I've only just started to look at the code, but it looks like FileBase.TrimString could be modified to care about TrimChars (or LineInfo.WhitespaceChars if TrimChars is null or empty).

bcallaghan-et commented 12 months ago

This is still an issue in 2023. When using a [FieldFixedLength] attribute in combination with a [FieldTrim(TrimMode.Right, '0')] (for example), the trailing zeros are not trimmed as expected. An examination of the source code shows that FieldBase.TrimChars is not used by the FieldBase.TrimString method.