Solved

delete a string of data in a file

Posted on 1998-01-21
1
123 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

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

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

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
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…

803 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