Reputation: 9380
I just can't get it right
The below statement throws an exception and I cannot get the correct format
$appendedQry = $appendedQry -replace "\"","'"
What would be the correct syntax?
Upvotes: 5
Views: 23419
Reputation: 1
I was replacing all occurances of the string in a file, using command
powershell -Command "(gc c:\input.txt) -replace 'aaa', 'bbb' | Out-File c:\output.txt"
To replace double quotes I need to do some trick - use the variable:
$ToReplace = "\" + """"
$command = "(gc c:\input.txt) -replace '" + $ToReplace + "', 'bbb' | Out-File c:\output.txt"
powershell -Command $command
Upvotes: 0
Reputation:
this because the escaping character is `
in the following a working example
$appendedQry = "`"asd"
echo $appendedQry
$appendedQry = $appendedQry -replace "`"", "'"
echo $appendedQry
Upvotes: 6