Jump to content

Need help in replacing string


Recommended Posts

I'm pretty sure that I have this file except it doesn't have an extension. This code returns an error:

 

$Dummies = @ScriptDir & "\Dummies"
$sFind = "109.99.99.99"
$sReplace = "No Longer Use"
    if FileExists($Dummies) Then
        _ReplaceStringInFile($Dummies,$sFind ,$sReplace)
    Else
        MsgBox(0, "Error", "Make sure Dummies file exist before you proceed to compile this project.")
        Return
    EndIf

 

If it has an extension then it's ok, but if it doesn't have an extension then it returns an error msgbox that I created. Any help is appreciated.

 

EDIT: I figured... I didn't show the extension. So it was Dummies.txt all along.

Edited by asianqueen

Msgbox(0, "Hate", "Just hate it when I post a question and find my own answer after a couple tries. But if I don't post the question, I can't seem to resolve it at all.")
Link to comment
Share on other sites

works just fine.  Are you sure it is there, and it does not have an extension?

 

and to clean up the above, which again works fine.

#include<file.au3>

$Dummies = @ScriptDir & "\Dummies"
$sFind = "109.99.99.99"
$sReplace = "No Longer Use"
    If FileExists($Dummies) Then
        _ReplaceStringInFile($Dummies,$sFind ,$sReplace)
    Else
        MsgBox(0, "Error", "Make sure Dummies file exist before you proceed to compile this project.")
    EndIf

 

,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-.
|(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/
(_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_)
| | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) (
| | | | |)| | \ / | | | | | |)| | `--. | |) \ | |
`-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_|
'-' '-' (__) (__) (_) (__)

Link to comment
Share on other sites

yeah it worked great... I have a new question; it's not an issue this time...

Is it possible to find the string and add additional strings below it? Not replacing it...

Msgbox(0, "Hate", "Just hate it when I post a question and find my own answer after a couple tries. But if I don't post the question, I can't seem to resolve it at all.")
Link to comment
Share on other sites

_ReplaceStringInFile($Dummies,$sFind ,$sFind & @CRLF & $sReplace)

 

,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-.
|(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/
(_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_)
| | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) (
| | | | |)| | \ / | | | | | |)| | `--. | |) \ | |
`-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_|
'-' '-' (__) (__) (_) (__)

Link to comment
Share on other sites

exactly what I needed...

Thank you so much for the previous info. It was pretty useful.

Edited by asianqueen

Msgbox(0, "Hate", "Just hate it when I post a question and find my own answer after a couple tries. But if I don't post the question, I can't seem to resolve it at all.")
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

×
×
  • Create New...