Replace


Definition: Returns a string in which a specified substring has been replaced with another substring a specified number of times.

 

The world as we know it would come to a crashing halt if we didn’t have search-and-replace commands. In Windows PowerShell you can do a simple search-and-replace on any string value simply by using the –replaceparameter and specifying two things:

 

·          The string value to search for.

·          The replacement text.

 

For example, the following two commandassign a value to the variable $a, then use –replace to replace all instances of the letter xwith the letter a:

 

$a = " bxnxnx"
$a = $a - replace(" x","a")

 

When you run this command and then echo back the value of $ a youshould get the following:

 

banana