当我尝试在 PS 5.1 中使用此处字符串时,出现红色曲线。我缺少什么?
function Main {
$csv = @"
test1,test2
"@
echo $csv
}
Main
Error:
White space is not allowed before the string terminator.
Note:
PowerShell 的这里的字符串 https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_quoting_rules#here-strings have 严格的语法要求closing分隔符 ('@
or "@
):
- 一定是at the 生产线的最开始- 甚至不空白允许在它之前.
这使得使用起来很棘手缩进代码,因为缩进无法维持,正如您所经历的:
@'
hi there
'@ # OK: closing delimiter is at the *very start* of the line.
@'
hi there
'@ # !! BROKEN -> error "White space is not allowed before the string terminator."
另外,请注意这里的字符串content也不支持缩进:
- 也就是说,第一个示例(工作示例)中生成的逐字值是
hi there
, i.e. 包括前导空白。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)