【发布时间】:2022-01-23 08:36:53
【问题描述】:
我正在尝试使用 PowerShell 将文本文件中的文本 ($) 替换为引号
这是我正在尝试的代码,但没有给出预期的结果:
$FilePath = "C:\PT\Test\"
Get-ChildItem $FilePath -Filter *.TXT | ForEach-Object {
(Get-Content $_.FullName) | Foreach-Object {
$_ -replace ',"$"', ',"$",'
} | Set-Content $_.FullName
}
【问题讨论】:
-
应该只需要转义它,尝试:
"\$","",或使用将逐字读取所有字符的点网方法:$_.Replace("$","")
标签: powershell powershell-2.0 powershell-3.0 powershell-4.0