How To Split a String With PowerShell

In this blog post, we are going to learn how to split a text string that has spaces, characters or signs using PowerShell and the split string method.

Split

The split method is one of the most powerful methods in PowerShell and allows us to split any text string using as you will see soon.

In my case, I have a string called “nt-weekly” which I am going to split the – sign from it using the split method.

The code below will remove the dash (-) sign and save the string in an array and print it.

$string = "nt weekly"
$newstring = $string.Split("-",[StringSplitOptions]'RemoveEmptyEntries')
$newstring

 


Posted

in

by