![](/img/trans.png)
[英]How to replace string with quotes and brackets in file using Powershell
[英]Using the replace operator on a string that has quotes powershell
我希望运行该命令
foreach-object {$_ -replace
但是,我试图使用的字符串可以描述如下
this string "has" quotes
整条线都是
foreach-object {$_ -replace "this string "has" quotes", "this string "won't have" quotes"}
如何使这个引用填充行与powershell一起工作?
你可以转义嵌套的双引号,如`"
或”更好,使用单引号引用字符串然后你不需要转义双引号,例如:
'this string "has" quotes'
注意:使用单引号,您不会在字符串中获得变量扩展。
您是否尝试将引号加倍作为引号的转义字符? 即
$a = "This String ""Has"" Quotes"
$a = $a.replace("This String ""Has"" Quotes","this string ""won't have"" quotes. ")
您可以将Grave(波浪号)双引号用作转义字符。 您可以对字符串中的任何特殊字符执行此操作。
例如
$a = "This String `"Has`" Quotes"
$a = $a.replace("This String `"Has`" Quotes","this string won't have quotes. ")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.