Jon8c Posted July 30, 2008 Posted July 30, 2008 Uh, hi, I'm back again... with another question: I'm trying to open a list of .txt files and replace certain strings within them with one string. So, I understand I could use _ReplaceStringInFile, but is it possible to to replace two characters and everything inbetwen them, regardless of what the innards might be? For instance, I could be trying to replace "(jack.what)" with "pizza" in one file. But, in another file its not "(jack.what)" but "(john.what)." Is it possible for AutoIt to somehow recognize the strings resembling a pattern, so that it could replace them, without having to actually specify what it exactly has to replace?
Paulie Posted July 30, 2008 Posted July 30, 2008 StringRegExpReplace() As per your example: $Test = "Blah Blah Blah this is sample text (john.what) more text (jack.what) even more text!!!! (OMFG DIFFERENT TEXT)" $Result = StringRegExpReplace($Test, "\((.*?)\)", "pizza"); replaces anything in parenthesis with "pizza" MsgBox(0,"","Before: " & @CRLF & $Test & @CRLF & @CRLF & "After: " & @CRLF & $Result)
Jon8c Posted July 30, 2008 Author Posted July 30, 2008 (edited) $handle=FileOpen("file.txt",0) $text1=FileRead($handle) $text2=StringRegExpReplace($text1,"\((.*?)\)","word") _ReplaceStringInFile("path\file.txt",$text1,$text2"",0) So, this would be how I would use that function to edit the file, right? Note: Nvm about this note, if you already read it before this last edit. I understand it now. Thanks. Edited July 30, 2008 by Jon8c
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