ssam
27th May 2008 08:59 UTC
replace a substring
Hello,
i want to search a substring in a File and replace it by another. in the following example, i want to replace a username by another.
ClearErrors
FileOpen $fp '$INSTDIR\bla.cfg' r
IfErrors notopen 0
pop $R0
FileRead $fp $R0
FileClose $fp_zedas.cfg
CopyFiles /FILESONLY '$INSTDIR\temp' '$INSTDIR\etc'
notopen:
in the bla.cfg stands for example:
[Point]
username = test
password = testuser
[Point2]
loglevel = 0
Logfile= ../log/logging.log
Ok, with fileread i get the file line by line and i musst loop, thats clear. but to find the unsername i can only search by username, because the line can also be "username = dog" etc. ... and not by the complete line.
if i have the line, i musst raplace the complete line by my new entry "username = $username".
Can anybody help my?
pospec
27th May 2008 09:09 UTC
Will this help you?
http://nsis.sourceforge.net/StrReplace_v4
ssam
27th May 2008 09:11 UTC
yes thanks,
but the first problem is to find the line to replace.
pospec
27th May 2008 09:15 UTC
Use documentation before asking.
http://nsis.sourceforge.net/Docs/AppendixE.html#E.2.2
ssam
27th May 2008 09:24 UTC
ok again:
i dont know the linenumber, so i must search .. FileRead
in every line i get, i must search a string, ... ( here im searching for a function)
edit: if my substring in the line,
than i replace the string , here i can use your first tip
you second tip finds only specified lines and the use for any string functions is also clear, but i can not use strcmp, because i dont know what string i get. and i can not use strfilter, because this function dont search for substrings
Afrow UK
27th May 2008 12:14 UTC
What is wrong with using WriteINIStr!?
Stu
pospec
27th May 2008 12:16 UTC
Ooops! I forgot this one since nsDialogs came on scene.
ssam
27th May 2008 12:36 UTC
Afrow see here http://forums.winamp.com/showthread....hreadid=289985
pospec i dont want any answer from you, thanks.
Afrow UK
27th May 2008 12:40 UTC
Your CFG file has section headers such as [Point] which is the same as INI files. In that topic he doesn't have any which is why he has to use ConfigWrite.
Stu
ssam
27th May 2008 12:44 UTC
ok thanks