$a = "192.168.2.1/25"
$a.Split("./")
192
168
2
1
25
192.168.2.1/25
> $PSVersionTable
Name Value
---- -----
PSVersion 6.0.4
PSEdition Core
GitCommitId v6.0.4
OS Linux 4.14.65-1-MANJARO #1 SMP PREEMPT Sat Aug 18 13:29:56 UTC 2018
Platform Unix
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
WSManStackVersion 3.0
PowerShell Core 6.0.4 installed on Manjaro Linux (Arch) via snapcraft
Performing a split operation with one delimiter, i.e.
> $a.Split('.')
still provides expected output:
> 192
> 168
> 2
> 1/25
Not sure what's the issue here... I'm using WSL Linux Ubuntu, and in PowerShell Core.
Are you trying to use the split method with two characters: "." and "/"? The following line work as expected.
PS /home/maxt> ($a.Split('.')).split('/')
192
168
2
1
25
PS /home/maxt>

I don't think the split method allows multiple characters.
Hi Max,
I'm trying to use multiple delimiters, as described in online resources. $a.Split('./')
Tested and working in Windows PowerShell 5.1.
(I'm not in close proximity of a personal windows machine at the moment, will try to get you a screenshot...)
Ah! Found some docs: https://docs.microsoft.com/en-us/dotnet/api/system.string.split?redirectedfrom=MSDN&view=netframework-4.7.2#overloads
It states that its possible to create an array of characters and then use the split() method. But I haven't figured it out how in PowerShell.
The following should work but it doesn't:
PS /home/maxt> [string[]] $sep = (".","/")
PS /home/maxt> $sep
.
/
PS /home/maxt> $a.Split($sep)
192.168.2.1/25
PS /home/maxt>
I got use to use the dual split().
:)
Good Catch!!
Ah! You didn't mention it work in Windows PowerShell. It's a bug!
:)
Either methods works in Windows PowerShell.
I'm sure it will be fix!

Is this what you want
PS> $a = "192.168.2.1/25"
PS> $a.split([char]".",[char]"/")
192
168
2
1
25
Tested and Works with v5.1, v6.0.4 and v6.1.0-preview4
Either works... But yes, using more than one delimirer in a Split command, e.g. Split('/ :;$.,') works for me in Windows PowerShell
It is not a bug, but an unfortunate - and unavoidable - consequence of a new method overload that is [string]-typed having been introduced in .NET _Core_.
This issue is therefore a duplicate of #3809; specifically:
https://github.com/PowerShell/PowerShell/issues/3809#issuecomment-302594098 explains the details (note that the options argument of the overload in question, public string[] Split (string separator, StringSplitOptions options = System.StringSplitOptions.None);, is optional)
https://github.com/PowerShell/PowerShell/issues/3809#issuecomment-302804271 explains why PowerShell, as a late-bound language, is _invariably_ susceptible to such changes in behavior.
The simplest solution is to cast to [char[]] or use .ToCharArray():
"192.168.2.1/25".Split([char[]] "./")
Thanks @mklement0!
Leave a comment
Thanks everyone!
Most helpful comment
It is not a bug, but an unfortunate - and unavoidable - consequence of a new method overload that is
[string]-typed having been introduced in .NET _Core_.This issue is therefore a duplicate of #3809; specifically:
https://github.com/PowerShell/PowerShell/issues/3809#issuecomment-302594098 explains the details (note that the
optionsargument of the overload in question,public string[] Split (string separator, StringSplitOptions options = System.StringSplitOptions.None);, is optional)https://github.com/PowerShell/PowerShell/issues/3809#issuecomment-302804271 explains why PowerShell, as a late-bound language, is _invariably_ susceptible to such changes in behavior.
The simplest solution is to cast to
[char[]]or use.ToCharArray():