• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 222
  • Last Modified:

How to replace a string for another one in a file

HI

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
0
dimensionav
Asked:
dimensionav
2 Solutions
 
StephenJRCommented:
You can use Find and Replace?
0
 
slightwv (䄆 Netminder) Commented:
Any reason you just don't open the file, read the line and use a replace then write it back out?

http://www.bigresource.com/VB-replace-string-in-a-text-file-Ebabm8JTCO.html
0
 
Muhammad KhanManager, 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")

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

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"
0
 
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.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now