[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 137
  • Last Modified:

Delete string from text file

how do i make my programme delete the string 'File was CFFed' that was found in 'C:\File data.txt'. the command will run when i click on a button.
0
tyfing
Asked:
tyfing
1 Solution
 
intheCommented:
hi,
heres one way:

procedure TForm1.Button1Click(Sender: TObject);
var
 sl : tstringlist;
  i : integer;
  s1 : string;
  SearchStr : string;
  place : integer;
begin
sl := tstringlist.create;
SL.LoadFromFile('C:\Winzip.log');
  SearchStr := 'File was CFFed';
  for i := 0 to SL.Count -1 do begin
    s1 := SL.Strings[i];
    Repeat
      Place := pos(SearchStr, s1);
      if place > 0 then begin
        Delete(s1, Place, Length(SearchStr));
        SL.Strings[i] := s1;
      end;
    until place = 0;
  end;
  sl.SaveToFile('C:\Winzip.log');
  sl.free;
end;
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now