Reputation: 611
Consider:
$str = 'My {token} string'
$newStr = $str.Replace('{token}', 'value')
$newStr
My value string
function strReplace ($str, $rval) { $str.Replace('{token}', $rval) }
$newStr = strReplace($str, 'value')
$newStr
My string
value
Even though string.Replace
returns a single string, an object[]
shows up in the return pipeline. Why? Is there a way to get the obvious return value?
Upvotes: 0
Views: 2138
Reputation: 29450
It's because you are passing in an array as the argument for $str
in your function. You need to call PowerShell functions like this (no brackets, no commas separating arguments):
$newStr = strReplace $str 'value'
Upvotes: 3