Skip to content
⌘ NSIS Forum Archive

Looking for a Line Replacing Function. Word ANYWHERE, Replace Entire Line

12 posts

vbgunz#

Looking for a Line Replacing Function. Word ANYWHERE, Replace Entire Line

I've been looking for something like this and I cannot find it. I need a function that will open a file for writing. It is looking for any word which means the word does not have to be[list=1][*]on a line by itself[*]starting the line off[/list=1]
It seems every function I've come across on the archives in no way happens to do what I am trying to get done. I am simply trying to find a word in a file and then replace that words entire line.

This word can and will be 99% of the time[list=2][*]NOT on a line by itself[*]NOT starting the line off[/list=2]
I've tried working on my own script to accomplish this but it seems I can only get as far as replacing the word ONLY if it is on a line by itself. Can someone help lend me a hand on this please. World of thanks!

PS. I'd like to call this task the Afrow UK challenge. Sorry Afrow 😉
vbgunz#
I feel I should be a bit more descriptive with the kind of function I am seeking.
  • It should not do a crazy loop. The new line might contain the old string again.
  • No new line should be created above or below the target line.
  • Possibility to find a string on the end of a line and replace ONLY everything before that string.
  • Anything else you feel might be important to a function o fthis nature.

major thanks to anyone who can help with this 🙂
vbgunz#
Here is that function created by the man 😉

Comm@nder21#
search the forums for WordFunc and TextFunc header files.

${WordFind}/${WordFind2X} and ${LineFind}/${LineRead} will do the trick.
Afrow UK#
vbgunz, the 2nd function you requested is ready. I shall upload it to the Archive now.

-Stu
Afrow UK#


It's a big function, but it works a brute!

-Stu
vbgunz#
Yak! I am certain the Function does as expected and I don't want you to change it so can you add a new Function with the ability to CopyBetween?

Ultimately, I was looking for a way to CopyBetween and put the copy into $0 and then use $0 as the value to ReplaceBetween. You understand?

Sorry if I mentioned it with misunderstanding. I do prefer though after looking at your function that they do stay seperated. Sharp.

File1
<yadda>
This is found in file1 and will be copied. A backup file exist and it is sort of like a database. It will basically serve so many different purposes.
<yadda />

File2
<yadda>
This is found in file1 and will be copied. A backup file exist and it is sort of like a database. It will basically serve so many different purposes.
<yadda />
Afrow UK#
I understand. I shall make a similar function called GetBetween.
Meanwhile, I updated the ReplaceBetween function to make it a tiny bit faster.

-Stu
Afrow UK#
Ok here it is:


-Stu