Strip the blank lines of a text file  

Send By: Radikal (Q3 Team)
Web : http://www.q3.nu
Email: radikal@q3.nu
Date: 29/08/20

Tip accessed 503 times

 


For example, a file whit this lines into:

 Line 1
 Line 2

 Line 4
 Line 5



Whit this function will be turned in:

 Line 1
 Line 2

 Line 4
 Line 5





 procedure TForm1.Button1Click(Sender: TObject);

   procedure StripBlankLines(TheFile: string);
   var
     Sl    : TStringList;
     p     : integer;
     sTemp : string;
   begin
     Sl:=TStringList.Create;
     try
       Sl.LoadFromFile(TheFile);
       sTemp:=Sl.Text;

       repeat
         P:=Pos(#13#10#13#10,sTemp);
         Delete(sTemp,P,2);
       until (P=0);

       Sl.Text:=sTemp;
       Sl.SaveToFile(TheFile);
     finally
       Sl.Free;
     end;
   end;

 begin
   StripBlankLines('c:\kk\TheFile.txt');
 end;