archies Posted November 14, 2007 Share Posted November 14, 2007 (edited) Hey guys,Say I have this test.txt file:The dog catcher chased the dog down the street. The dog chased the cat down the street. The cat chased the mouse down the street. The mouse got away from the cat. The cat got away from the dog. The dog got away from the dog catcherOk now I want to read this file into an array so:#include <File.au3> Dim $MyArray _FileReadToArray(c:\test.txt, $MyArray)I'm not sure what the "Dim" thing is for but I've seen it used when someone else helped me the other day with another problem so I'm assuming it is needed.Anyways, now I want to perform a couple of operations on "$MyArray" and one of them is to do some basic "find and replace" text.So for this example, I want to replace the word "street" with the word "road" in the whole "$MyArray". And also the word "got" with the word "ran".So if I were to do a _FileWriteFromArray at this point, I would get a txt file that looks like this:The dog catcher chased the dog down the road. The dog chased the cat down the road. The cat chased the mouse down the road. The mouse ran away from the cat. The cat ran away from the dog. The dog ran away from the dog catcherHope it's all clear.Thanks for the help guys!PS: I tried to do StringReplace($MyArray,street,road) but it seems to have no affect Edited November 14, 2007 by archies Link to comment Share on other sites More sharing options...
smashly Posted November 14, 2007 Share Posted November 14, 2007 Hi, #include <File.au3> Global $TestFile = @ScriptDir & "\test.txt" Dim $MyArray _FileReadToArray($TestFile, $MyArray) For $i = 1 To $MyArray[0] If StringInStr($MyArray[$i], "street") Then $MyArray[$i] = StringReplace($MyArray[$i], "street", "road") Next _FileWriteFromArray($TestFile, $MyArray, 1) Cheers Link to comment Share on other sites More sharing options...
archies Posted November 14, 2007 Author Share Posted November 14, 2007 Awesome! thanks so much man! I was close to figuring it out on my own but I knew something I was doing had to be wrong. Thanks man 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