Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Read through a file and replace certain parts...

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
I have a major problem, I'm starting my A2 computing course after the summer, in which I have to create a delphi project.... the problem is I don't know anything about delphi. At 6th Form we are using Delphi 6 professional. But actually we aren't using it and we never have, this is due to the appalling teachers we have...

To give you an example of how bad they are, we are working on MS Access, and my friend gets stuck on a query, asks for the teachers help... and the teacher comes over to his computer and presses F1, which brings up the annoying paper clip assistant, then he walks off. Great. How are we supposed to learn anything.

So now know you understand why I know nothing about delphi... but am stuck in the middle of a Delphi course. I need your help... I am confident with other languages, and I am familiar with the functions available so if you could help give me a pointer I would be very grateful...

For part of my project which I have started at home already (So I get extra time over the holiday period) I need to get Delphi to read through a file, in this case a HTML application called 'Structure.hta' and replace everything enclosed in # or similar to be replaced with a variable set using delphi. For example replace #colour# with Delphi variable colour.

If anybody is fluent in Delphi 6, I desperately need the code to be able to do the above, my university placement is at stake.
Thanks for your help and patience reading this message.
Please contact me A.S.A.P
amk221@aol.com

 
Hi,

as i understand, all you need is load a text file and replace some words. Try this:

Code:
var
  SL: TStringList;
  I: Integer;
begin
  SL := TStringList.Create;
  SL.LoadFromFile('yourfile.html');  //load file
  for I := 0 to SL.Count - 1 do
    StringReplace(SL[I], 'oldWord', 'newWord', [rfIgnoreCase, rfReplaceAll]); //replace all ocurrences of the old word with the new word
  SL.SaveToFile('yourfile.html');       //save file
  SL.Free;                              //clear memory
end;
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top