String methods and arrays
In PowerShell, you can call some string methods on an array. PowerShell automatically unrolls the array and executes the method. Array unrolling applies when accessing properties as well; however, this does not apply to strings.The method will be executed against each of the elements in the array. For example, the Trim method is used against each of the strings as follows:
PS> ('azzz', 'bzzz', 'czzz').Trim('z')
a
b
c
The Split method is also capable of acting against an array, the result of the following example is a single array containing four elements:
PS> ('a,b', 'c,d').Split(',')
a
b
c
d
This remains true if the array object does not have a conflicting method or property. For example, the Insert
method cannot be used as an array object has a version of its own.
Properties and methods of array elements
The array unrolling feature demonstrated here has broader scope than methods...