Easy string manipulation with VBScript using the Replace Function
Posted by: Jerry Lees
Recently, I had a situation at the office where I needed to check a web.config file for the existence of a setting. Not a hard problem– just open the file up an look for it, however, that becomes a little harder when your talking about 30 servers. So, I scripted it using the replace function!
The replace function in VBScript is an invaluable tool in very many scripts, especially when you want to simply check for the existence of a string in another string or completely replace a string with another string. Its simplest syntax is fairly straightforward as well, it is:
NewString = Replace (Searchedstring, FindString, Replacewithstring)
This one function allows you to completely change a file by searching for the value in the string(s) read into a variable then saving the new variable into the file. Or you can do a comparison on the new variable with the old one to see if they are equal, if they aren’t the string was found and replaced.
All in all, Replace is an invaluable tool to put in your scripting arsenal.




