连接

"abc" + "def"    =>    abcdef

"abc" * 3    =>    abcabcabc

 

-Join(一元联接运算符):

一元联接运算符 (-join <string[]>) 的优先级高于逗号。因此,如果向一元联接运算符提交逗号分隔的字符串列表,则只有第一个字符串(第一个逗号之前的部分)才会提交给联接运算符。
若要使用一元联接运算符,请将字符串用圆括号括起,或将字符串存储在变量中,然后提交该变量以进行联接。
例如:

-join "a", "b", "c"
返回结果:
a
b
c

-join ("a", "b", "c")
返回结果:
abc

$z = "a", "b", "c"
-join $z
返回结果:
abc

   

"Windows", "PowerShell", "2.0" -join " "  #返回结果:Windows PowerShell 2.0

$a = "Windows", "PowerShell", "2.0"  

-join $a  #返回结果:WindowsPowerShell2.0 

$a -join ";"  #返回结果:Windows;PowerShell;2.0 

   

$b=@'
a
b
c
'@

(-split $b) -join ""  #返回结果:abc

posted @ 2015-05-10 20:33  dongdonggeorge  阅读(212)  评论(0编辑  收藏  举报