Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/powershell/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
对包含引号powershell的字符串使用替换运算符_Powershell_Quotes - Fatal编程技术网

对包含引号powershell的字符串使用替换运算符

对包含引号powershell的字符串使用替换运算符,powershell,quotes,Powershell,Quotes,我正在运行命令 foreach-object {$_ -replace 但是,我尝试使用的字符串可以描述为 this string "has" quotes 全线 foreach-object {$_ -replace "this string "has" quotes", "this string "won't have" 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. ")
您可以将双引号(平铺键)作为转义字符。您可以对字符串中的任何特殊字符执行此操作

e、 g

$a = "This String `"Has`" Quotes"
$a = $a.replace("This String `"Has`" Quotes","this string won't have quotes. ")