PowerShell Split String Operation With Examples

RSS
EMAIL
FACEBOOK
FACEBOOK
GOOGLE
GOOGLE
https://www.poftut.com/powershell-split-string-operation-examples/
PINTEREST
PINTEREST
INSTAGRAM

Powershell provides string type methods to the string objects. Split is one of them. Split method is used to split string into separate parts or a string array. In this tutorial we will look different usage types and examples of Split.

Specify Separator

While splitting a text or string we can provide a separator to split them. We will provide as argument to the split function. Function names are incase sensitive. We will provide space as separator in this example.

Each separated element is printed in a new line.

Split With Multiple Separators

In some situations there may be more than one separator. Another useful feature of split function is we can specify multiple separators by adding more split functions and related separator in a string mode. In this example we will define two separator like space and point.

First we create our separator variable.

Then we provide $separators variable to the split function.

Split According To Regex

For more structured but complex strings and text regex based separator can be used. In this example we will use t and s characters as separator by specifying in regex.

Split According To Regex
Split According To Regex

Split Mac Address

Another useful example will be splitting the mac address into hexadecimal parts.

We get all parts of the mac address in a new line. If we need we can loop in them using foreach.

LEARN MORE  Python Regular Expression Operations - Regex

RSS
EMAIL
FACEBOOK
FACEBOOK
GOOGLE
GOOGLE
https://www.poftut.com/powershell-split-string-operation-examples/
PINTEREST
PINTEREST
INSTAGRAM

Leave a Reply

Your email address will not be published.