내가 문자열을 delimitted구문 분석 정의 인수 "-"
- 자동차 : "닛산"-Model : "디나"- 컬러 : "라이트 블루"-wheels : "4"
어떻게 인수를 추출 할 수 있습니까? 초기 생각은 구분 기호로 '-'를 사용하는 것이었지만 작동하지는 않습니다.
내가 문자열을 delimitted구문 분석 정의 인수 "-"
- 자동차 : "닛산"-Model : "디나"- 컬러 : "라이트 블루"-wheels : "4"
어떻게 인수를 추출 할 수 있습니까? 초기 생각은 구분 기호로 '-'를 사용하는 것이었지만 작동하지는 않습니다.
정규 표현식을 사용하는 것이 가장 쉬운 방법 일 수 있습니다. 이는 PowerShell에서 수행 할 수 있습니다
$text = @'
-car:"Nissan" -Model:"Dina" -Color:"Light-blue" -wheels:"4" -windowSize.Front:"24"
'@
# assume parameter values do not contain ", otherwise this pattern should be changed
$pattern = '-([\.\w]+):"([^"]+)"'
foreach($match in [System.Text.RegularExpressions.Regex]::Matches($text, $pattern)) {
$param = $match.Groups[1].Value
$value = $match.Groups[2].Value
"$param is $value"
}
출력 :이 PowerShell을에
car is Nissan
Model is Dina
Color is Light-blue
wheels is 4
windowSize.Front is 24
관련되는 방법? – stej