On Jun 15, 6:53*am, tonycd <ton...@xxxxxx> wrote:
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
The string you want to work with in the second replace is no longer
the version in the variable strText. It was changed and stored in
strNewText by the first replacement, so in the second line the correct
variable to work against is strNewText, as in ...
strNewText = Replace(strText, "Jim ", "James ")
****strNewText = Replace(strNEWText, "abc ", "apple ")
Tom Lavedas
************