Skip navigation
Split string with PowerShell

Split string with PowerShell

Q. How can i split a PowerShell string into parts?

A. PowerShell strings have a split function that enables the simple splitting of a string into an array of strings based on a delimiter character.

The example below splits based on the space character and removes any entries that have no actual content.

$FullName = "John Savill "
$Names = $FullName.Split(" ",[StringSplitOptions]'RemoveEmptyEntries')

$Names would contain two entries: John and Savill. The trailing spaces were removed.

Hide comments


  • Allowed HTML tags: <em> <strong> <blockquote> <br> <p>

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.