Page 1 of 1

Whitespace in Fixed Width file

Posted: Thu Feb 24, 2011 12:05 pm
by Ragunathan Gunasekaran
Hi,

I am writing two columns with data type as decimal(16,2) followed by a charater field into a sequential file with the properties set as Record Delimiter = DOS style and Field Delimiter as None. I have removed the rest of record level and field level properties.

The code run is good but the data was not as expected. I could see a whitespace character at the start of the decimal fields.

Code: Select all

 00000000000100.00 00000000000001.00Other Banks
Any clue of how to get rid of this whitespace.


Note: The third character field is appearing as expected

Posted: Thu Feb 24, 2011 2:59 pm
by jwiles
The whitespace you're seeing is in fact the placeholder for the sign of the number. By default, for a positive number it is a space, for a negative number it would be '-'. The default conversion from decimal to string returns a string that is two bytes longer than the length of the decimal: one byte for the sign, one byte for the decimal point '.'.

If you just wish to get rid of the space, you can use StripWhitespace() or one of the Trim() functions. Keep in mind that in doing so, negative numbers will still contain the '-' and would therefore be longer than non-negative numbers.

Alternatively, you could use Convert() to change the space to a plus symbol '+' and maintain the length integrity.

Regards,