"tonycd" <tonycd@xxxxxx> wrote in message
news:74DABA76-6B73-4153-9926-2726ABF13D41@xxxxxx
Quote:
> Hi
>
> I just copy the script from Microsoft web site that for replace the text.
> But how can i enhance the script for multi - text replacement. Thanks
> i try with this (i put the star in front of script) , but it doesn't work.
>
> regards
> Tony
>
> Const ForReading = 1
> Const ForWriting = 2
>
> Set objFSO = CreateObject("Scripting.FileSystemObject")
> Set objFile = objFSO.OpenTextFile("C:\Scripts\Text.txt", ForReading)
>
> strText = objFile.ReadAll
> objFile.Close
> strNewText = Replace(strText, "Jim ", "James ")
> ****strNewText = Replace(strText, "abc ", "apple ")
>
> Set objFile = objFSO.OpenTextFile("C:\Scripts\Text.txt", ForWriting)
> objFile.WriteLine strNewText
> objFile.Close
>
>
You could nest your "Replace" function:
strNewText = Replace(Replace(strText, "Jim ", "James "), "abc", "apple")
or even better:
strNewText = Replace(Replace(strText, "Jim ", "James ",1,-1,1),"abc",
"apple",1,-1,1)