The VBScript Network and Systems Administrator's Cafe

Oct 1 2008   2:06PM GMT

Easy string manipulation with VBScript using the Replace Function



Posted by: Jerry Lees
Tags:
Functions
Replace
String manipulation
VBScript
VBScript Functions

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.

 Comment on this Post

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when other members comment.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to: