Huy Than
Huy Than

Reputation: 1546

How to split output using brace symbol as delimiter in Windows command line?

In Windows command line, I got the output like this:

{D1AB12B0-B9B5-43A0-98E1-584D790524FE} Kaspersky for Windows

I am looking for a solution to split the above string into variables using } as delimiter.

Any help is appreciated.
Thank you.
Huy

Upvotes: 1

Views: 233

Answers (1)

Viktor
Viktor

Reputation: 32

Use .split() or -split with the desired delimiter. It makes an array out of those splitted parts, which you can than use by index and save it into a variable:

$string = '{D1AB12B0-B9B5-43A0-98E1-584D790524FE} Kaspersky for Windows'

$GUID = $string.split('}')[0].substring(1)
$ProductName= $string.split('}')[1].trim()

In my code .substring() and .trim() is just used for formatting purpose.

Upvotes: 1

Related Questions