Monthly Archive

Categories

Playing with the range operator

The range operator allows you to reference a range of numbers

1..10

 

is equivalent to

1,2,3,4,5,6,7,8,9,10

 

If you want anything other than numbers you’re stuck as the range operator only works with integers

though you can have a decrementing list

10..1

 

65..74 | foreach {[char]$psitem}

would be A – J

 

If you want A-Z

65..90 | foreach {[char]$psitem}

 

For lowercase letters (a – z)  use

97..122 | foreach {[char]$psitem}

 

You can even work from an array of values

$data = 'value1','value2','value3','value4','value5','value6','value7','value8','value9','value10'

$data[3..6]
$data[6..3]

Comments are closed.