0
4

1 回答 1

1

I guess you just do it this way:

$OptionNum = (Read-Host “Enter the required options”) -split ','|%{if($_){$_.trim()}}

The result string of Read-Host gets splitted in the commas and the you loop over that array asking if there is a value (if for some reason your user leaves a comma at the end or their input begins with a comma) you trim the trailing whitespaces at the beginning and end (because if user input is '1, 2, 3, 4,6 , 7' or something among those things users like to do)

于 2021-03-23T03:45:10.363 回答