Here is an example of splitting strings by a delimiter.
- First, we are setting a variable $days with values with a comma as a delimiter.
- Then, splitting the variable by defining a comma as a delimiter.
PS C:\Users\codetryout> $days = "Sun,Mon,Tue,Wed,Thu,Fri,Sat"
PS C:\Users\codetryout> $days -split ","
Sun
Mon
Tue
Wed
Thu
Fri
Sat
PS C:\Users\codetryout>
Here is another example of a split using a hyphen as the delimiter
First, setting a variable.
$CodeTryout="code-try-out"
To print that whole variable on screen:
$CodeTryout
To print it
$CodeTryout.split("-")
All together in practice:
Note: This is tested in Windows 11, Powershell version: 5.1, and we used commas and hyphens here in examples. However, any characters can be used as a delimiter.