本文介绍了将字符串附加到数组的每个项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

这篇关于将字符串附加到数组的每个项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

05-28 19:21
查看更多