Why does using an ArrayList prints numbers?
The ArrayList.Add
method always returns the index of the new item that you add:
PS > $ArrayList = New-Object System.Collections.ArrayListPS > $ArrayList.Add('a')0PS > $ArrayList.Add('b')1PS >
You can suppress this output by either casting to [void]
:
PS > $ArrayList = New-Object System.Collections.ArrayListPS > [void]$ArrayList.Add('a')PS >
or by redirecting the output to $null
:
PS > $ArrayList = New-Object System.Collections.ArrayListPS > $ArrayList.Add('a') > $nullPS >
ArrayList.Add() returns the index at which the value was added. Get rid of this output by redirecting to $null or casting to [void]
.
$ArrayList.Add($subString) > $null
or
[void]$ArrayList.Add($subString)