Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Read File containing EOF (AscII 26) chars into StringList

Status
Not open for further replies.

rwblinn

Programmer
Jan 3, 2001
3
DE
How can I read a file which contains more EOF chars (ascii 26) into a stringlist? using read or blockread does not work so far, since these functions stop reading at the first EOF char found and the rest of the file conatining some EOF chars is not read in anymore.
 
Using a StringList solves this problem for me. I find that some DOS editors put a #26 into text files which I need to remove. Something like this should work:-

Code:
var
  txt: TStringList;
  temp: string;
  p: integer;
begin
  txt := TStringList.Create;
  try
    txt.LoadFromFile ( FileName );
    temp := txt.Text;
    p := Pos ( #26, temp );
    while p > 0 do begin
      Delete ( temp, p, 1 );
      p := pos ( #26, temp );
    end;
    txt.text := temp;
    txt.SaveToFile ( FileName );
  finally
    txt.free;
  end;
end;

Andrew
 
Thanks. I have tried it and found a problem that loadfromfile stops reading if a ascii 00 (blank) is found. How can I overcome this?
As a try I have changed the 00 to 32 by using my favorite ultraedit, saved and then tried your example again. went perfect.
 
Have you tried using a File of Char with BlockRead? And then manually traversing the characters, changing them as needed? Never too old to learn...
Nico
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top