MichaelHooker
Programmer
I use Delphi 7 in Win XP SP2.
One of my programs loads a text file into a StringList for processing. After 7 months of daily files, the external provider has somehow started producing files where each line ends with not one but two carriage returns and a linefeed. When viewed in NotePad the files look perfectly normal, but a hex editor clearly shows "0D 0D 0A" at the end of every line rather than the previous "0D 0A".
When the file is loaded into a StringList using .LoadFromFile(), the resulting StringList consists of alternating lines of data and blank lines and as you can imagine the unexpected blank lines play havoc with my processing.
The same behaviour occurs with, eg:
the result being that data lines alternate with blank lines in the Memo.
The fact that two lines are being created from one is also illustrated by the fact that if I use .SaveToFile() from the StringList or Memo, and then load the resulting file into NotePad, I get alternate blank lines: in the hex viewer there is "0D 0A 0D 0A" between each row of text!
I could I suppose include a new line in the processing loop which says:
But there should be a more elegant way, shouldn't there? And if NotePad can successfully ignore the extra CR character why can't Delphi components?
I have no control over the format of the input file or how it is produced: so the answer to this problem cannot be "get the input file format changed back to what it was like before"!
I would provide an example program to play with but I can't work out how to reproduce a sample of the source file, short of an attachment to this post and it doesn't seem possible to do that.
Thanks in any advance for any helpful comments and suggestions.
Michael Hooker
One of my programs loads a text file into a StringList for processing. After 7 months of daily files, the external provider has somehow started producing files where each line ends with not one but two carriage returns and a linefeed. When viewed in NotePad the files look perfectly normal, but a hex editor clearly shows "0D 0D 0A" at the end of every line rather than the previous "0D 0A".
When the file is loaded into a StringList using .LoadFromFile(), the resulting StringList consists of alternating lines of data and blank lines and as you can imagine the unexpected blank lines play havoc with my processing.
The same behaviour occurs with, eg:
Code:
Memo1.Lines.LoadFromFile(FileName);
the result being that data lines alternate with blank lines in the Memo.
The fact that two lines are being created from one is also illustrated by the fact that if I use .SaveToFile() from the StringList or Memo, and then load the resulting file into NotePad, I get alternate blank lines: in the hex viewer there is "0D 0A 0D 0A" between each row of text!
I could I suppose include a new line in the processing loop which says:
Code:
if LineString <> '' then begin
etc;
etc;
end;
But there should be a more elegant way, shouldn't there? And if NotePad can successfully ignore the extra CR character why can't Delphi components?
I have no control over the format of the input file or how it is produced: so the answer to this problem cannot be "get the input file format changed back to what it was like before"!
I would provide an example program to play with but I can't work out how to reproduce a sample of the source file, short of an attachment to this post and it doesn't seem possible to do that.
Thanks in any advance for any helpful comments and suggestions.
Michael Hooker