2012-11-22 4 views
2

나는이 아이디어를 더 잘 수행 할 방법이 필요합니까?다중 분할

$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] 

하나의 문자열에 너무 많은 분할 기능을 사용하는 팬이 아닙니다. 내가 뭘 할 수 있을까?

위의 예에서 개별 해상도 크기, 색상 수 및 빈도를 변수에 저장하려고합니다.

가로 세로 = 800 = 600 = I 색 우리 분할 기능 문자의 배열을 전달할 수 있음을 발견 한 60

답변

6

32 주파수 =.
그래서, 한 줄에 :

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

32 
bits 
@ 
60 
Hz. 
+0

당신 선생님, 천재이다. – Anicho

2

한 가지 방법은 다음과 같습니다

$strOutput = "800x600, 32 bits @ 60 Hz." 
$splitted = $strOutput -replace '\D',' ' -split '\s+' 
$strHorizontal = $splitted[0] 
$strVertical = $Splitted[1] 
$strColour = $splitted[2] 
$strFrequency = $splitted[3]