如果发现逗号,请分割数组

时间:2019-02-28 18:36:55

标签: powershell

$FruitArray[0] = "Banana, Orange, Peach, Mangoes"
$FruitArray[1] = "Apple, Banana"
$FruitArray[2] = "Peach"
$FruitArray[3] = "Mangoes"

如何拆分数组项以获得以下结果?

$FruitArray[0] = "Banana"
$FruitArray[1] = "Orange"
$FruitArray[2] = "Peach" 
$FruitArray[3] = "Mangoes"
$FruitArray[4] = "Apple"
$FruitArray[5] = "Banana"
$FruitArray[6] = "Peach"
$FruitArray[7] = "Mangoes"

1 个答案:

答案 0 :(得分:2)

以逗号分隔数组元素,并将结果分配回该变量。

$FruitArray = $FruitArray -split ',\s*'