Find & Replace script – Expanded

Home Forums Scripting Windows Script Host Find & Replace script – Expanded

Viewing 1 post (of 1 total)
  • Author
    Posts
  • Avatar
    CaTBuS
    Member
    #155145

    I have the following Find/Replace script and it works fine. What I’m wanting to do and am unable to figure out is how to expand the script to find and replace multiple strings. I am still learning am am certain that I’m missing some simple bit of basic know-how. Anyway, here is what I have:

    Code:
    [COLOR=”Blue”]Const[/COLOR] ForReading = [COLOR=”Red”]1[/COLOR]
    [COLOR=”blue”]Const[/COLOR] ForWriting = [COLOR=”red”]2[/COLOR]

    [COLOR=”blue”]Set[/COLOR] objFSO = CreateObject(“[COLOR=”Gray”]Scripting.FileSystemObject[/COLOR]”)
    [COLOR=”blue”]Set[/COLOR] objFile = objFSO.OpenTextFile(“[COLOR=”Gray”]C:ScriptsTest.txt[/COLOR]”, ForReading)

    strText1 = objFile.ReadAll
    objFile.Close
    strNewText1 = Replace(strText1, “[COLOR=”gray”]server.location1″, “server[/COLOR]”)

    [COLOR=”blue”]Set[/COLOR] objFile = objFSO.OpenTextFile(“[COLOR=”gray”]C:ScriptsTest.txt[/COLOR]”, ForWriting)
    objFile.WriteLine strNewText1
    objFile.Close

    Here is one of the many ways I have tried to do this to no avail. In addition to assistance with the actual correct code, I would love an explanation as to why my logic doesn’t work. Thank you in advance:

    Code:
    [COLOR=”Blue”]Const[/COLOR] ForReading = [COLOR=”Red”]1[/COLOR]
    [COLOR=”blue”]Const[/COLOR] ForWriting = [COLOR=”red”]2[/COLOR]

    [COLOR=”blue”]Set[/COLOR] objFSO = CreateObject(“[COLOR=”Gray”]Scripting.FileSystemObject[/COLOR]”)
    [COLOR=”blue”]Set[/COLOR] objFile = objFSO.OpenTextFile(“[COLOR=”Gray”]C:ScriptsTest.txt[/COLOR]”, ForReading)

    strText1 = objFile.ReadAll
    objFile.Close
    strNewText1 = Replace(strText1, “[COLOR=”gray”]server.location1″, “server[/COLOR]”)

    [COLOR=”blue”]Set[/COLOR] objFile = objFSO.OpenTextFile(“[COLOR=”gray”]C:ScriptsTest.txt[/COLOR]”, ForWriting)
    objFile.WriteLine strNewText1
    objFile.Close

    strText2 = objFile.ReadAll
    objFile.Close
    strNewText2 = Replace(strText2, “[COLOR=”gray”]server.location2″, “server[/COLOR]”)

    [COLOR=”blue”]Set[/COLOR] objFile = objFSO.OpenTextFile(“[COLOR=”gray”]C:ScriptsTest.txt[/COLOR]”, ForWriting)
    objFile.WriteLine strNewText2
    objFile.Close

Viewing 1 post (of 1 total)

You must be logged in to reply to this topic.