Solved

delete a string of data in a file

Posted on 1998-01-21
1
121 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 Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
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…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

708 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now