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
Solved

delete a string of data in a file

Posted on 1998-01-21
1
124 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: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

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

Title # Comments Views Activity
Delphi Firemonkey Need Sample for Online Shopping Example. 2 166
FMX and jaudiotracker playing memory stream 29 85
DBGrid or StringGrid ? 6 103
update joined tables 2 55
This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

791 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