将字符串附加到数组的每个项目数组、字符串、项目

由网友(天会亮、心会暖)分享简介:I have an array and when I try to append a string to it the array converts to a single string.I have the following data in an array: $Str 451 CAR,-3 ,7 ,10 ,...

I have an array and when I try to append a string to it the array converts to a single string.

I have the following data in an array:

$Str  
451 CAR,-3 ,7 ,10 ,0 ,3 , 20 ,Over: 41  
452 DEN «,40.5,0,7,0,14, 21 ,  Cover: 4  
Labview如何把字符串数组转为字符串

And I want to append the week of the game in this instance like this:

$Str = "Week"+$Week+$Str 

I get a single string:

Week16101,NYG,42.5 ,3 ,10 ,3 ,3 , 19 ,Over 43 102,PHI,-  1,14,7,0,3, 24 ,  Cover 4 103,

Of course I'd like the append to occur on each row.

解决方案

Instead of a for loop you could also use the Foreach-Object cmdlet (if you prefer using the pipeline):

$str = "apple","lemon","toast" 
$str = $str | ForEach-Object {"Week$_"}

Output:

Weekapple
Weeklemon
Weektoast

阅读全文

相关推荐

最新文章