Skip to content

about_Split: Make it clearer that -split also supports string arrays (collections) as input #1640

@mklement0

Description

@mklement0

about_Split currently shows the following syntax:

-Split <String>

<String> -Split <Delimiter>[,<Max-substrings>[,"<Options>"]]

<String> -Split {<ScriptBlock>} [,<Max-substrings>]

This suggests that only a string scalar is supported as input, whereas you can actually pass string arrays (collections) and have the splitting logic applied to each array/collection element individually, with the resulting element-specific token arrays getting concatenated.

I suggest changing the syntax diagram to:

-Split <String>
-Split (<String[]>)

<String[]> -Split <Delimiter>[,<Max-substrings>[,"<Options>"]]

<String[]> -Split {<ScriptBlock>} [,<Max-substrings>]

Note that, for the unary form, I'm proposing separate representations for the scalar and the array operand form, so as to highlight the need to enclose the operand in (...) when passing an array literal (due to operator precedence) - this is not a concern for the binary form.

There are scattered reference to the support for arrays, but I think they're not enough and they're partially incorrect (emphasis added):

If you submit multiple strings, all the strings are split using the same delimiter rules.

As a result, if you submit a comma-separated list of strings to the unary split operator, only the first string (before the first comma) is split.
To split more than one string, use the binary split operator ( -split ).

As the subsequent -split ("1 2", "a b") example demonstrates, the unary form supports multiple strings too (as long as literals are (...) enclosed).

Version(s) of document impacted

  • Impacts 6 document
  • Impacts 5.1 document
  • Impacts 5.0 document
  • Impacts 4.0 document
  • Impacts 3.0 document

Metadata

Metadata

Assignees

Labels

Pri3Priority - Low

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions