StevensNet.com

...Because someone's gotta tell the story...

Blogs

To return to the main Blog List, click Full Blog Listing.

Tags

PowerShell
VBScript

Multiplication of Replace

Thursday, May 12, 2016 in Powershell (Views: 1493)
This is just a quick one, but a feature that is unique to PowerShell that makes it better than say your old VB/VBScript. To define something for replace in VBScript, you had to do something like the following:

dim string1 as string
String1="Some text needs to be replaced"
String1=Replace(String1,"Some","Not All")
String1=Replace(String1,"needs","should be")


In PowerShell (starting in v3), you can actually combine these into one statement by using multiple replace commands:

$string1="Some text needs to be replaced"
$string1=$string1.Replace("Some","Not All").Replace("needs","should be")


Great time saving tip in a pinch. Happy scripting.

 

Related Blogs You May Be Interested In:


To leave a comment, please log in and/or register.