string - Powershell加入

标签 string powershell join

我试图使用此方法将数组的多个元素连接到字符串中;

$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/

相关文章:

python - 在 BeautifulSoup 中打印和格式化结果

c++ - 检查字符串是否包含非字母数字字符

java - 在java中构建字符串的二叉搜索树

powershell - 寻找纯 PowerShell IRC 客户端

python - 你如何加入列表中的所有项目?

python - 语法错误 :update for dictionary

powershell - 找不到奇怪的路径名的路径原因

powershell - 如何保存已删除文件的日志?

mysql - WHERE 连接表

MYSQL错误和连接语句