Find/Replace in text file?

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hello,

Can anyone help me on how to find and replace text within a .txt file using
vb.net?

Any help would be greatly appreciated!
Thanks in advance.
 
Dim fso, inputFile, outputFile
Dim str As String

fso = CreateObject("Scripting.FileSystemObject")

'1 means for reading

inputFile = fso.OpenTextFile("c:\testfile.txt", 1)

str = inputFile.ReadAll

'modify this string, replace required characters

str = Replace(str, "whatToReplace", "replaceWithThis")

'write back

outputFile = fso.CreateTextFile("c:\testfile.txt", True)

outputFile.Write(str)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top