Archive: replace a substring


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?

Will this help you?
http://nsis.sourceforge.net/StrReplace_v4


yes thanks,

but the first problem is to find the line to replace.


Use documentation before asking.
http://nsis.sourceforge.net/Docs/AppendixE.html#E.2.2


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


What is wrong with using WriteINIStr!?

Stu


Ooops! I forgot this one since nsDialogs came on scene.


Afrow see here http://forums.winamp.com/showthread....hreadid=289985

pospec i dont want any answer from you, thanks.


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


ok thanks