I need to know how many replacements Powershell makes when using the -replace or Replace() operator. Or, if this is not possible, if it will replace it at all.
For example, in Perl, since the substitution operation returns the number of replacements made, and zero returns false, while a nonzero value true in a Boolean context, you can write:
$greeting = "Hello, Earthlings"; if ($greeting ~= s/Earthlings/Martians/) { print "Mars greeting ready." }
However, with Powershell, the operator and method return a new line. It seems that the operator provides some additional information if someone knows how to request it (for example, the captured groups are stored in a new variable that it creates in the current area), but I canβt find out how to get the score or success value.
I could just compare the values ββbefore and after, but that seems completely ineffective.
Justin R.
source share