Solved

delete a string of data in a file

Posted on 1998-01-21
1
126 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

752 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