| $s = @' | | 中 0x0001 国 | | | | 日 0x0003 本 | | | | 新加 0x000F 坡 | | | | 南 0x0011 非 | | | | 美 0x000A 国 | | | | 澳大 0x0010 利亚 | | '@ | | | | $str=($s -replace '(\r\n){2}',"`r`n" -split '\r\n') | | [System.Collections.Generic.Dictionary[int,string]]$coll=@{} | | $result=($str|sort{[int](($_ -split ' ')[1])}) | | | | $result|%{$coll[((($_ -split ' ')[1]))]=$_} | | $rs=$result|%{($_ -split ' ')[1]} | | $min=$rs[0] | | $max=$rs[$rs.Count-1] | | $c=0;$min=foreach($i in $min..$max){ | | if($coll.Keys -notcontains $i){$i;$c++} | | if($c -gt 0){break} | | } | | $coll.Add($min,'0x{0:x4}' -f $min) | | $coll.ValuesCOPY |
不知是不是这个意思呢? |