powershell 用于连接多个字符串

问题描述 投票:0回答:2

在Powershell中,如何将5个字符串连接成一个字符串。

 $s1='This`-string
 $s2='is' -string
 $s3='a'  -string
 $s4='good' -string
 $s5='thing' -string
 $s6=$s1+$s2+$s3+$s4+$s5
 write-host"result is "$s6-->Thisisagoodthing 
powershell concatenation
2个回答
3
投票

您可能会使用:

> $s6="$s1$s2$s3$s4$s5"
>
> Write-Host "result is $s6"

1
投票

您可以使用

-join
运算符“连接”字符串:

$s6 = $s1,$s2,$s3,$s4,$s5 -join ""

或者,不指定分隔符:

$s6 = -join @($s1,$s2,$s3,$s4,$s5)
© www.soinside.com 2019 - 2024. All rights reserved.