Split string with variable whitespace characters in Powershell

You can use PowerShell’s -split operator which uses regular expressions.

"Video  Video  Audio  Audio  VBI    VBI" -split '\s+'

As noted by @StijnDeVos, this does not remove leading/trailing whitespace.

Here, the \s represents whitespace characters, and the + matches one or more of them. All the more reason to go with @user3554001’s answer.

Another option is to filter the empty strings.

 "Video  Video  Audio  Audio  VBI    VBI".split()| where {$_}

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)