albator Posted August 30, 2005 Share Posted August 30, 2005 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. Link to comment Share on other sites More sharing options...
dman Posted August 30, 2005 Share Posted August 30, 2005 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 constantsConst ForReading = 1Const ForWriting = 2'create scripting objectSet objFSO = CreateObject("Scripting.FileSystemObject")Set objFile = objFSO.OpenTextFile(InFile, ForReading)'read the file to string variablestrText = objFile.ReadAll'close the fileobjFile.Close'do the rerplacements, add one line for each replacementstrText = Replace(strText, "http://", " ")strText = Replace(strText, "ftp:", " ")'write corrected string to fileSet objFile = objFSO.OpenTextFile(OutFile, ForWriting)objFile.WriteLine strText'close the file'objFile.Close Link to comment Share on other sites More sharing options...
albator Posted August 31, 2005 Author Share Posted August 31, 2005 Thank alot but a script wich script ? What do I do with this text save it with an extension name ? 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 constantsConst ForReading = 1Const ForWriting = 2'create scripting objectSet objFSO = CreateObject("Scripting.FileSystemObject")Set objFile = objFSO.OpenTextFile(InFile, ForReading)'read the file to string variablestrText = objFile.ReadAll'close the fileobjFile.Close'do the rerplacements, add one line for each replacementstrText = Replace(strText, "http://", " ")strText = Replace(strText, "ftp:", " ")'write corrected string to fileSet objFile = objFSO.OpenTextFile(OutFile, ForWriting)objFile.WriteLine strText'close the file'objFile.Close<{POST_SNAPBACK}> Link to comment Share on other sites More sharing options...
dman Posted August 31, 2005 Share Posted August 31, 2005 (edited) save as text with .VBS extension, like "textreplace.vbs" or something. Then dblclick or from cmd prompt do "cscript textreplace.vbs" Edited August 31, 2005 by dman Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now