tags:

views:

424

answers:

1

How do I replace text from one file with text from another file using vbscript?

The text being replaced is somewhere in the middle of the file.

+2  A: 

filea.txt: hello cruel world

fileb.txt: cruel

filec.txt: happy

will make sResult = "hello happy world" after the following has executed.

Dim oFSO
Dim sFileAContents
Dim sFileBContents
Dim sFileCContents
Dim sResult
Set oFSO = CreateObject("Scripting.FileSystemObject")
sFileAContents = oFSO.OpenTextFile("c:\filea.txt").ReadAll()
sFileBContents = oFSO.OpenTextFile("c:\fileb.txt").ReadAll()
sFileCContents = oFSO.OpenTextFile("c:\filec.txt").ReadAll()
sResult = Replace(sFileAContents, sFileBContents, "")
svinto