Unable to replace "$" in a string

Viewed 68

I want to replace "$" from a string in PowerShell. I am trying this:

PS> $vars
abcd$
PS> $vars -replace "`$"
abcd$

How to replace the "$" in the string?

1 Answers

The -replace operator uses regular expressions for string matching thus you have to escape the dolar using a backslash:

$vars -replace "\$"

Cheers!

Related