我试图使用此方法将数组的多个元素连接到字符串中;
$a = "h","e","l","l","o"
$b = [string]::join("", $a[0,1,2,3])
但是我在方法调用中收到“Missing')'错误。连接文档仅提及连接数组的所有元素,而不提及特定索引处的元素。能做到吗?
干杯
安迪
最佳答案
将“$ a [0,1,2,3]”的内容换成“$()”或“()”
PS> [string]::join("", $($a[0,1,2,3]))
hell
PS> [string]::join("", ($a[0,1,2,3]))
hell
- 或者 -
您可以使用范围运算符“..”
PS> [string]::join("", $a[0..3])
hell
关于string - Powershell加入,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/617369/