且构网

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

powershell 替换特殊字符

更新时间:2023-09-17 23:37:34

使用 Escape 方法在运行时转义特殊字符.您不需要转义替换模式:

Use the Escape method to escape special characters at run time. You don't need to escape the replace pattern:

(Get-Content c:\dump\xml) | 
ForEach-Object {$_ -replace [regex]::Escape('<?xml version="1.0"?>'),'<?xml version="2.0"?>'} | 
Set-Content c:\dump\xml