我想在PowerShell中重复一个字符。例如:
$test = "this is a test that I want to underline with --------"
Write-Host $test
Write-Host "-" * $test.length
但是,上面的代码输出为:
This is a test that I want to underline with --------
- * 53
我是否真的缺少明显的东西?
改变:
Write-Host "-" * $test.length
到:
Write-Host $("-" * $test.length)
在参数模式下,解析器将解释"-" * $test.length
为三个单独的可扩展字符串-将它们包含在一个子表达式($()
)中,以便在将整个表达式作为参数参数绑定之前对其进行评估。
您可能想要Get-Help about_Parsing
。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句