Jump to content

StringReplace() error.. How to fix it?


Recommended Posts

Hello

I'm trying to read a .txt file and if the specific searchstring was found then it should be replaced but it doesn't work :/

What am I doing wrong below?

$text = "test1.txt"

$readtext = FileReadLine($text)

If StringInStr($readtext, "Hello") Then
    StringReplace($text,"Hello","Goodbye")
    MsgBox(1,"Status","Hello was found and has been replaced")
Else
    MsgBox(0,"Status","Hello wasn't found in test1.txt")
EndIf

Regards

Link to comment
Share on other sites

First thing, you are trying to perform StringReplace() on $text, which should be $readtext.

Second, if you are expecting this to update your file, it won't. You need to find _ReplaceStringInFile in the User Defined Functions part of the help file.

Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...