Help - Search - Members - Calendar
Full Version: advanced search and replace program needed
MSFN Forums > Coding, Scripting and Servers > Web Development (HTML, Java, PHP, ASP, XML, etc.)

   
Google Internet Forums Unattended CD/DVD Guide
albator
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.
dman
This is quick-and-dirty script for text replacement. Edit to suit...
CODE
'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
albator
Thank alot but a script wich script ? What do I do with this text save it with an extension name ? blink.gif

QUOTE (dman @ Aug 30 2005, 05:02 PM)
This is quick-and-dirty script for text replacement. Edit to suit...
CODE
'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

*
dman
save as text with .VBS extension, like "textreplace.vbs" or something. Then dblclick or from cmd prompt do "cscript textreplace.vbs"
Google Internet Forums Unattended CD/DVD Guide
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.