自然排序

$a="a1","a2","a3","a4","a5","a6","a7","a8","a9","a10","a11","a12"

Sort中的Property 参数的值可以是新的计算属性。若要创建计算属性,使用哈希表,其实就是相当于新添加了一个Property进行排序:

方法一:

$a| sort @{e= {$_ -replace 'a' -as [int]}}

方法二:

$ToNatural = { [regex]::Replace($_, '\d+', { $args[0].Value.PadLeft(20) }) }
$a | Sort-Object -Property $ToNatural

结果:

posted on 2014-11-12 10:07  momingliu11  阅读(390)  评论(0编辑  收藏  举报