且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Powershell -replace 当替换字符串包含 $+

更新时间:2023-11-07 16:11:22

你可以像这样使用 .Replace() 方法,而不是使用 -replace 操作符:

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

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

.Replace() 方法来自 .NET String 类,而 -Replace 运算符是使用 System.Text.RegularExpressions.Regex.Replace 实现的().

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

此处的更多信息:https://vexx32.github.io/2019/03/20/PowerShell-Replace-Operator/