Just Code‎ > ‎

Powershell - Replace function with ignore case

posted Oct 14, 2011, 12:02 AM by Peter Henell   [ updated Jan 16, 2012, 2:10 PM ]
A small example of how to use RegEx to replace something in a string ignoring their case.
function ReplaceString{
param([String]$str, [String]$oldValue, [String]$newValue)
   
   $value = [System.Text.RegularExpressions.Regex]::Replace($str, $oldValue, $newValue, [System.Text.RegularExpressions.RegexOptions]::IgnoreCase)
   $value
}

Example of usage:
$spText = ReplaceString -str $storedProcedureText -oldValue "CREATE PROCEDURE" -newValue "ALTER PROCEDURE"
Comments