Question:
My array is spits out this.
1 2 3 4 5 6 7 8 |
a10 a11 a12 a6 a7 a8 a9 |
Any short/simple code to fix it to:
1 2 3 4 5 6 7 8 |
a6 a7 a8 a9 a10 a11 a12 |
Answer:
You can sort by expression, take everything after the first letter and cast it to integer:
1 2 |
$array | sort { [int]$_.substring(1)} |
You can also make the solution more generic by removing any non-digit characters:
1 2 |
$array | sort { [int]($_ -replace '\D')} |