zvd Posted June 14, 2005 Share Posted June 14, 2005 Hello, I have a file that has several lines in it that may contain the following: Users="adomain.user" or Users="adomain.user","another.user" etc. There may be 1 to 5 different "adomain.user" entries in that line. Using StringReplace, I'm trying to remove the entire line, and replace it with Users="mydomain.myuser". The code I'm using removes the User= alright, and replaces it with Users="mydomain.myuser" OK, but leaves all the other "adomain.user" entries. Could anyone tell me how to achieve what I'm trying to do? Code: $szFile = "c:\temp\reg.ini" $var = "Users=" $answer = ("Users="""& @LogonDomain &"."& @Username & """") $szText = FileRead($szFile,FileGetSize($szFile)) $szText = StringReplace($szText, $var, $answer) FileRecycle($szFile) FileWrite($szFile,$szText) Link to comment Share on other sites More sharing options...
/dev/null Posted June 14, 2005 Share Posted June 14, 2005 "adomain.user" entries. Could anyone tell me how to achieve what I'm trying to do?Use FileReadLine() and check each line for "user=". If the string is part of the line, replace it with a new line and write it to a tempfile with FileWriteLine.If the string is NOT part of the line, write the original line to a tempfile with FileWriteLine.See helpfile for FileReadLine(), etc.CheersKurt __________________________________________________________(l)user: Hey admin slave, how can I recover my deleted files?admin: No problem, there is a nice tool. It's called rm, like recovery method. Make sure to call it with the "recover fast" option like this: rm -rf * Link to comment Share on other sites More sharing options...
zvd Posted June 14, 2005 Author Share Posted June 14, 2005 Unfortunately, there are also alot of lines in the file with user in it (without the =). It seems that FileReadLine ignores the = when I specify user=, and returns all lines with user in it. Link to comment Share on other sites More sharing options...
/dev/null Posted June 14, 2005 Share Posted June 14, 2005 It seems that FileReadLine ignores the = when I specify user=, and returns all lines with user in it.????$file = FileOpen("C:\test.txt") $newfile = FileOpen("C:\testnew.txt") while 1 $line = FileReadLine($file) if @error = -1 then exitloop if StringInStr($line, "user=") then $newline = "myuser=xxxxxx"; or whatever you like here !! FileWriteLine($newfile, $newline) else FileWriteLine($newfile, $line) endif wend FileClose($file) FileClose($newfile)CheersKurt __________________________________________________________(l)user: Hey admin slave, how can I recover my deleted files?admin: No problem, there is a nice tool. It's called rm, like recovery method. Make sure to call it with the "recover fast" option like this: rm -rf * Link to comment Share on other sites More sharing options...
zvd Posted June 15, 2005 Author Share Posted June 15, 2005 Thanks alot for the help! That worked. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now