Powershell -replace when replacement string contains $+

前端 未结 4 1849
被撕碎了的回忆
被撕碎了的回忆 2020-12-07 00:08

I am doing a string replacement in PowerShell. I have no control over the strings that are being replaced, but I can reproduce the issue I\'m having this way:



        
4条回答
  •  青春惊慌失措
    2020-12-07 00:36

    Instead of using the -replace operator, you can use the .Replace() method like so:

    PS> 'word'.Replace('word','@#$+')
    @#$+
    

    The .Replace() method comes from the .NET String class whereas the -Replace operator is implemented using System.Text.RegularExpressions.Regex.Replace().

    More info here: https://vexx32.github.io/2019/03/20/PowerShell-Replace-Operator/

提交回复
热议问题