以下代码效率很差,纠结中...
#include <array.au3>
Dim $array[21] = ['czr1.5', _
'czr1.6abc', _
'opear1000ab', _
'cxd5.9', _
'opear5.6', _
'64.1auto123', _
'4cxd0.25df5', _
'cadll8.613', _
'czr48as26', _
'opear5855as85', _
'45cxd0.25f', _
'auto984', _
'opear354df', _
'czr48', _
'opear5855', _
'45cxd0.25', _
'auto984', _
'opear354', _
'541auto1.3', _
'cadll861', _
'auto984dfa']
$timer = TimerInit()
$out=string_number($array)
_ArrayDisplay($out,TimerDiff($timer))
Func string_number($array)
Local $num=1
For $i=0 To UBound($array)-1;取列
$tmp=StringRegExp($array[$i],'\d+|[^\d]+',3)
If UBound($tmp)>$num Then $num=UBound($tmp)
Next
Local $new_array[UBound($array)][$num+2]
Local $new_len[$num+1]
For $i=1 To $num;定义第列长度
$new_len[$i]=1
Next
For $i=0 To UBound($array)-1;取每列字符串长度
$temp=StringRegExp($array[$i],'\d+|[^\d]+',3)
$new_array[$i][0]=$array[$i]
For $n=1 To UBound($temp)
$new_array[$i][$n]=$temp[$n-1]
$nl=StringRegExp($temp[$n-1],'\d+',3)
If @error Then
If StringLen($temp[$n-1])>$new_len[$n] Then $new_len[$n]=StringLen($temp[$n-1])
Else
If StringLen($nl[0])>$new_len[$n] Then $new_len[$n]=StringLen($nl[0])
EndIf
Next
Next
For $i=0 To UBound($new_array)-1;将每列格式化
For $n=1 To UBound($new_array,2)-2
$format='%0'&$new_len[$n]&'s'
If $new_array[$i][$n]='' Then
$new_array[$i][$n]=StringFormat($format,0)
ElseIf StringRegExp($new_array[$i][$n],'\d+',0) Then
$new_array[$i][$n]=StringFormat($format,$new_array[$i][$n])
EndIf
Next
Next
For $i=0 To UBound($new_array)-1;将格式化后文本写入
Local $string=''
For $n=1 To UBound($new_array,2)-2
$string&=$new_array[$i][$n]
Next
$new_array[$i][UBound($new_array,2)-1]=$string
Next
_ArraySort($new_array,0,0,0,UBound($new_array,2)-1)
Local $output[UBound($new_array)]
For $i=0 To UBound($new_array)-1
$output[$i]=$new_array[$i][0]
Next
Return $output
EndFunc
|