如果您缩进vscode,则此字符串不起作用

具有预期的效果:

$toAdd = @"
{
"name": $SomeVar,"value" : "app"
}
"@

但是如果我缩进-tyo在函数中保留一些结构可以说: 注意“ linex”只是为了说明缩进

 line1:     $toAdd = @"
 line2:     {
 line3:     "name": $SomeVar,line4:     "value" : "app"
 line5:     }
 line6:     "@

然后我得到:White space is not allowed before the string terminator.PowerShell

有什么办法解决吗?

szv123_rier 回答:如果您缩进vscode,则此字符串不起作用

我很乐意被证明是错误的(请!),但是,不行,heredoc字符串需要格式化而无需缩进Powershell才能理解。

$heredocHaiku = @"
I have to be left
flush against the console's start
to be recognized
"@
,

您可以只在脚本顶部声明 Here-String,然后将适当的 Scope Modifier 应用于变量。那么你就不必担心缩进,snf 让它看起来很难看,比如如果 here-string 嵌套在 function 中:

# Top of script
$script:code = @"
Hear ye,hear ye
Here's a here-string
"@
本文链接:https://www.f2er.com/3158262.html

大家都在问