![](/img/trans.png)
[英]PowerShell - escaping fancy single and double quotes for regex and string replace
[英]Powershell replace double quotes with single in a string
我只是無法做對
以下語句拋出異常,我無法獲得正確的格式
$appendedQry = $appendedQry -replace "\"","'"
什么是正確的語法?
它應該是
$appendedQry = $appendedQry -replace '"',''''
因為逃避的角色是`
在下面的一個工作示例中
$appendedQry = "`"asd"
echo $appendedQry
$appendedQry = $appendedQry -replace "`"", "'"
echo $appendedQry
我正在使用命令替換文件中字符串的所有出現
powershell -Command "(gc c:\input.txt) -replace 'aaa', 'bbb' | Out-File c:\output.txt"
要替換雙引號,我需要做一些技巧 - 使用變量:
$ToReplace = "\" + """"
$command = "(gc c:\input.txt) -replace '" + $ToReplace + "', 'bbb' | Out-File c:\output.txt"
powershell -Command $command
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.