vickerps Posted July 23, 2004 Share Posted July 23, 2004 I want to replace part of a line of text For example this is line 1 this is line 2 this is line 3 this is line 23 the number is NO this is line 24 the number is NO this is line 25 this is line 33 the number is NO The number you require is NO That annoying number you want is NO Please phone NO for assistance How do i replace 'NO' with say '12345678' throughout the text file hope this make sense Link to comment Share on other sites More sharing options...
Davman Posted July 23, 2004 Share Posted July 23, 2004 Scan the entire file line by line, set variable to the line contents $text = StringReplace("<line contents>", "NO", "123456789") Write string back to the line you read out of. Sitting comfortably behind the code. Link to comment Share on other sites More sharing options...
vickerps Posted July 23, 2004 Author Share Posted July 23, 2004 how do write the string back to the text file Link to comment Share on other sites More sharing options...
sugi Posted July 23, 2004 Share Posted July 23, 2004 (edited) You might want to check the help file for anything that contains "file" or "write" in its name or ask about the specific problems you have. Edited July 23, 2004 by sugi Link to comment Share on other sites More sharing options...
Davman Posted July 23, 2004 Share Posted July 23, 2004 I believe what sugi meant to say was: FileWriteLine(<filename>, <line>) Sitting comfortably behind the code. Link to comment Share on other sites More sharing options...
vickerps Posted July 23, 2004 Author Share Posted July 23, 2004 thanks i figured it out after i spent the time to look at it properly _FileReadToArray( "c:\list.txt", $temp ) For $n = 1 to $temp[0] $temp[$n]= StringReplace($temp[$n],$MidToChange, Guiread($MID)) FileWrite("tempfilename.txt",$temp[$n]) IF $n < $temp[0] THEN FileWrite("tempfilename.txt",@lf) Next FileCopy("tempfilename.txt","c:\list.txt",1) FileDelete("tempfilename.txt") 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