Hentie Posted March 16, 2005 Posted March 16, 2005 Please Help! Something that was supposed to be quite simple just turned out to be "impossible". I just can't get my head around this. My problem: I've got a string in a text file that I want to find and replace but it seems impossible. I can't find a string in a text file without opening the file as read only and if I open the file in write mode then I can't do a FileRead and only have 2 write options: 1. Append to the end of the file 2. Overwite the entire contents of the file. I'm obviously missing something? This is what I've got so far: if FileExists ($FileName) Then $file = FileOpen($FileName, 0) if Not($file = -1) Then While 1 $line = FileReadLine($file) ;Msgbox (0, 'line', $line) If @error = -1 Then ExitLoop $s = StringInStr($line, $Customstr) if not($s=0) Then MSGBOX (0, "Match Found", $line) ;Now replace the string...????? EndIf Wend EndIf FileClose($file) EndIf
SlimShady Posted March 16, 2005 Posted March 16, 2005 (edited) Functions you need: - _FileReadToArray (see help file for info) - FileOpen in overwrite mode - StringReplace - FileWriteLine Edited March 16, 2005 by SlimShady
automagician Posted March 16, 2005 Posted March 16, 2005 I was just going to give you the solution, but you'll learn more if you do it on your own with the functions from Slim...just give a shout if you still need help....
Hentie Posted March 16, 2005 Author Posted March 16, 2005 Thanks to you guys it turned out to be easy after all.
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