我正在尝试使用Powershell为Visual Studio生成build.include脚本。它们都使用${variable}
作为引用变量的方式。
我想知道是否有办法将其转义为字符串。
例如
$string = @'
This is a `${string} I want to escape and {0} one I do not want to
'@ -f $Var
我在网上看了一下,它说要逃避$,您必须使用反引号。似乎对变量不起作用吗?
答案 0 :(得分:0)
也许使用以下语法:
$Var = 'one'
$string = @"
This is a `$Var I want to escape and {0} I do not want to
"@ -f $Var
$string
生成以下输出:
This is a $Var I want to escape and one I do not want to
另一个选择是嵌入变量:
@"
This is a `${Var} I want to escape and $Var I do not want to
"@
一些评论:
@""@
之间答案 1 :(得分:0)
我知道了。您必须将双括号。
示例:
$string = @'
This is a ${{string}} I want to escape and {0} one I do not want to
'@ -f $Var