How to split a string content into an array of strings in PowerShell?

Spread the love

Question Description

I have a string that has email addresses separated by semi-colon:

$address = "[email protected]; [email protected]; [email protected]"

How can I split this into an array of strings that would result as the following?

[string[]]$recipients = "[email protected]", "[email protected]", "[email protected]"

Practice As Follows

As of PowerShell 2, simple:

$recipients = $addresses -split "; "

Note that the right hand side is actually a case-insensitive regular expression, not a simple match. Use csplit to force case-sensitivity. See about_Split for more details.

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.