My array is spits out this.
a10
a11
a12
a6
a7
a8
a9
Any short/simple code to fix it to:
a6
a7
a8
a9
a10
a11
a12
                You can sort by expression, take everything after the first letter and cast it to integer:
$array | sort { [int]$_.substring(1)}
You can also make the solution more generic by removing any non-digit characters:
$array | sort { [int]($_ -replace '\D')}
                        The easiest way in this case would be to zero-pad all numbers and use that for sorting:
$a | sort {
  [Regex]::Replace($_, '\d+', 
  {
    $args[0].Value.PadLeft(10, '0')
  })
}
                        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