Skip to content

Instantly share code, notes, and snippets.

@kayasax
Created April 29, 2015 10:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kayasax/182cde4cd2c7300b006c to your computer and use it in GitHub Desktop.
Save kayasax/182cde4cd2c7300b006c to your computer and use it in GitHub Desktop.
Suppression de lignes vides après un split
# some ways to remove empty lines when splitting strings
# for example
# $text = "Video Video Audio Audio VBI VBI"
# $text.Split()
# outputs this
# Video
# Video
# Audio
# Audio
# VBI
# VBI
# 1. using powershell -split as unary operator
-split $text
# 2. Using powershell -split operator (use regular expression)
$text -split '\s+' #Here, the \s represents whitespace characters, and the + matches one or more of them.
# 3. Filter not null elements
$text.split()| where {$_}
# 3. using the .net split method :
$text.split(" ",[System.StringSplitOptions]::RemoveEmptyEntries)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment