erundil
15th April 2011 14:02 UTC
Text editing, Find and Replace: Find beginning of the line, change what goes after
Ok, I'll try to keep this brief.
I need help.
What I want to do is open a text file like this:
Blah blah
Blah
SettingName1=abc
SettingName2=xyz
and then:
Save a value of Setting 1 into a variable, and then let user choose an option, what should be placed instead of abc.
What I need are two functions:
- one that finds text in file and then saves the rest of the line into a variable
- second that finds text in file and then replaces the rest of the line with a value given by parameter.
Anyone knows how to achieve it?
I found an odd function that does something similar, backwards, but couldn't change it to anything usefull for me (http://nsis.sourceforge.net/Replace_...ring_on_a_line). I don't get this stack Exch/Push thing. :/
I'm not the best programmer, but someone have to make an installer for our game translations... and it came up for me. _-_
Afrow UK
15th April 2011 14:10 UTC
Try ConfigRead/ConfigWrite from the manual.
Stu
erundil
17th April 2011 14:33 UTC
Thanks for the tip. I'll give it a try.
There is far way from 2 commands to functional script... but maybe if I spend a couple of nigths on it...
erundil
17th April 2011 16:44 UTC
Yeah, easier than I thought.
Code is short and clear - I didn't even need to create separate functions.
It works like this:
We need to !include TextFunc.nsh. Then we read it. If we have a line:
Setting1=ABC
We can read "ABC" into a variable ($0) with this code:
${ConfigRead} "<path to the file>\filename.fileext" "Setting1=" $0
Once we have read ABC, we want to replace it with something, let's say with "XYZ"
We create a backup of the file, and then we use this:
${ConfigWrite} "<path to the file>\filename.fileext" "Setting1=" "XYZ" $0
That's it. two lines of code. And to think, that I expected, that I would need a whole functions.
Thank's Stu.