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!

NEWBIE Help! Searching for text and inserting some more 1

Status
Not open for further replies.

Delphiwhat

Programmer
Apr 1, 2003
74
0
0
EU
Hi folks

Sorry if this sounds trivial but what i'm trying to do is as follows:

I have a text file like this....
[price]bla bla bla [description]bla bla bla[Author]bla bla blabla bla blabla bla blabla bla blabla bla blabla bla bla

What i want to do is open the file
search for the text label "[description]"
immediately after this insert some more text which is available in a memo box or something.
then save the file

any ideas?

Thanks in advance!
 
One way is read the file, search for the keyword and write the text to another file. If you need to maintain the same file name, what you can do is at the end of the process, delete the original file and rename back the new file to the original filename.
 
It sounds like you're dealing with an initialization (ini) file. Try looking up TIniFile in the Delphi help. Something like this excerpt from the helpfile may be useful:
Code:
var
  AppIni: TIniFile;
begin
  AppIni := TIniFile.Create('MyIniFile.INI');
  AppIni.ReadSectionValues('description',ListBox3.Items);
  AppIni.Free;
end;

Hope this helps! Clive [infinity]
Ex nihilo, nihil fit (Out of nothing, nothing comes)
 
Thanks so far... Basically the file is a html file that i want to read in as raw text. search for the <HEAD> tag and insert a script immediately after it and save the file.

The reason i want to automate this is because i have 130 files i need to add this script to

thanks
 
You can create a Tstringlist variable, then LoadFromFile the text file. Set the delimiter with .delimiter:=' ' to find individual words.

Then, parse through the Tstring list and use Comparetext(.strings,targetword) to find a match. You can use .Add to add a string.

However, it works for me as i am always adding text in the same position, whereas there may be issues with sorting of the list and keeping its integrity. May be somewhere to start though. There is some stuff in the helpfile, but I could post my code later if you think it may help.

 
I don't know the solution to your problem, but I do have one advice (which might be redundant).

Be sure to put this script in a file of it's own (*.js for javascript) and have the code added to the html files &quot;include&quot; this script. Otherwise you're in for a long coffee run if you ever have to update the script...
 
Thanks everyone for your help. I thing i'll be able to get it sorted now

cheers

jc
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top