multiple splittings

powershell, split, string

Solution

I've found that we can pass an array of chars to the split function. So, in one line :

PS C:\Windows\system32> "800x600, 32 bits @ 60 Hz.".split(@("x",","," "))
800
600

32
bits
@
60
Hz.

Problem

I need a better way of doing this any ideas? ``` $strOutput = "800x600, 32 bits @ 60 Hz." # Initial split $aSplitString = $strOutput.Split(",") # Get Horizontal and Vertical Length $aSplitString2 = $aSplitString[0].Split("x") $strHorizontal = $aSplitString2[0] $strVertical = $aSplitString2[1] $aSplitString2 = $null #Get Color Depth and Frequency $aSplitString2 = $aSplitString[1].Split(" ") $strColour = $aSplitString2[1] $strFrequency = $aSplitString2[4] ``` Not a fan of using so many split functions on one string. What else could I do? I am trying to get the individual resolution sizes, the color depth and the frequency into their on variables in the above example; horizontal = 800 vertical = 600 color = 32 frequency = 60

Original source