Given:
I'd like to take the csv integers and make it look like the following:
$parmIn = "100,200"
desired output: "(100),(200)"
The way it is currently done:
$parmIn = "100,200"
$x = "(" + "$parmIn".replace(",", "),(") + ")"
What's another way to write this more concisely in PowerShell?
I was thinking something with array subexpressions or something.
Use the regex-based -replace operator:
"100,200" -replace '\d+', '($&)' # -> "(100),(200)"
Regex \d+ matches one or more (+) decimal digits (\d)
In the replacement expression, $& refers to what each \d+ match captured.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With