Question:
I am looking to run the command
1 2 |
foreach-object {$_ -replace |
However the string I am attempting to work with could be described as the follow
1 2 |
this string "has" quotes |
the whole line being
1 2 |
foreach-object {$_ -replace "this string "has" quotes", "this string "won't have" quotes"} |
How do I make this quote filled line work with powershell?
Answer:
You can either escape the nested double quotes like so `"
or better yet, use single quotes for quoting of the string then you won’t need to escape the double quotes e.g.:
1 2 |
'this string "has" quotes' |
Note: with single quotes you won’t get variable expansion in a string.