Solved

delete a string of data in a file

Posted on 1998-01-21
1
125 Views
Last Modified: 2010-05-18
How do you delete a string of data if you know what the string should contain?. ex. I want to delete the line lastdrive=w from my autoexec.bat.
I use Delphi 3.
0
Comment
Question by:hh
1 Comment
 
LVL 5

Accepted Solution

by:
inter earned 50 total points
ID: 1357260
Use the following funcion

// call example : RemoveFromFile('c:\Autoexec.bat','lastdrive=w')
// this procedure deletes every occurring line of Substr
// so be carefull and modify the program accordingly

function RemoveFromFile(FileName, SubStr : string):boolean;
var
  S : TStringlist;
  i : integer;
begin
  S := TStringList.Create;
  try
    S.LoadFromFile(FileName); // load file
    for i:= S.Count-1 downto 0 do
      if Pos(UpperCase(SubStr), UpperCase(S[i])) then
        S.Delete(i);
    S.SaveToFile(FileName); // override file
  finally
    S.Free;
  end;
end;

May it works,
Igor
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

735 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question