Jump to content

Recommended Posts

Posted

I would like to be able to do a multiple search and replace ? does someone know how ?

for example search a texte for 'http://' and 'ftP:' and reblace both by a blank space in a txt file. Please Help with this.


Posted

This is quick-and-dirty script for text replacement. Edit to suit...

'set input and output files (can be the same)
Const InFile = "C:\test\test.txt"
Const OutFile = "C:\test\test.txt"

'set file open mode constants
Const ForReading = 1
Const ForWriting = 2
'create scripting object
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile(InFile, ForReading)

'read the file to string variable
strText = objFile.ReadAll

'close the file
objFile.Close

'do the rerplacements, add one line for each replacement
strText = Replace(strText, "http://", " ")
strText = Replace(strText, "ftp:", " ")

'write corrected string to file
Set objFile = objFSO.OpenTextFile(OutFile, ForWriting)
objFile.WriteLine strText

'close the file'
objFile.Close

Posted

Thank alot but a script wich script ? What do I do with this text save it with an extension name ? :blink:

This is quick-and-dirty script for text replacement. Edit to suit...
'set input and output files (can be the same)
Const InFile = "C:\test\test.txt"
Const OutFile = "C:\test\test.txt"

'set file open mode constants
Const ForReading = 1
Const ForWriting = 2
'create scripting object
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile(InFile, ForReading)

'read the file to string variable
strText = objFile.ReadAll

'close the file
objFile.Close

'do the rerplacements, add one line for each replacement
strText = Replace(strText, "http://", " ")
strText = Replace(strText, "ftp:", " ")

'write corrected string to file
Set objFile = objFSO.OpenTextFile(OutFile, ForWriting)
objFile.WriteLine strText

'close the file'
objFile.Close

Posted (edited)

save as text with .VBS extension, like "textreplace.vbs" or something. Then dblclick or from cmd prompt do "cscript textreplace.vbs"

Edited by dman

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...