How to replace a string for another one in a file


I have a text file that contains a big string and I need replace part of it, something like this:

"This a big string inside a file" and I need to do this "This a modified string inside a file"

Thanks in advance
Who is Participating?
slightwv (䄆 Netminder)Connect With a Mentor Commented:
Any reason you just don't open the file, read the line and use a replace then write it back out?
You can use Find and Replace?
Muhammad KhanConnect With a Mentor Manager, ITCommented:
set FSO = CreateObject("Scripting.FileSystemObject")
Dim fileStream
Dim s
Set fso =

Set fileStream = fso.OpenTextFile("c:\workshop\File1.txt", 1)
s = Replace(fileStream.ReadAll, "This a big string inside a file", "This a modified string inside a file")

Set fileStream = fso.OpenTextFile("c:\workshop\File1.txt", 2)
fileStream.Write (s)
dimensionavAuthor Commented:

The string that will be replaced is very specific and the new string is created by a query, actually I need to do some kind of automated "find and replace"
slightwv (䄆 Netminder) Commented:
I'm not following why you cannot open file , read contents ,replace string, write new string, close file.

wither using the code in the example I posted or snippet provided by aiklamha.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.