$begin=TimerInit()
$fc=FileRead("a.txt")
$array=StringRegExp($fc,"\r\n\r\n\:([\s\S]+?)(?=\r\n\r\n\:)",3)
Dim $thestr[UBound($array)]
for $i = 0 to UBound($array) - 1
$thestr[$i]=$array[$i]
Next
$array=StringRegExp($fc,"\A\:([\s\S]+?)\r\n\r\n\:[\s\S]*\z",1)
If Not @error Then
Local $an=UBound($thestr)
ReDim $thestr[$an+1]
$thestr[$an]=$array[0]
EndIf
$array=StringRegExp($fc,"(?:[\s\S]+?\r\n\r\n\:)*([\s\S]*)\z",1)
If Not @error Then
Local $an=UBound($thestr)
ReDim $thestr[$an+1]
$thestr[$an]=$array[0]
EndIf
For $i=0 To UBound($thestr)-1
For $j=$i To 0 Step -1
If $j>0 And StringLeft($thestr[$j],1)<StringLeft($thestr[$j-1],1) Then
$tmpval=$thestr[$j]
$thestr[$j]=$thestr[$j-1]
$thestr[$j-1]=$tmpval
EndIf
Next
Next
$thelast=":"&$thestr[0]
For $i=1 To UBound($thestr)-1
$thelast=$thelast&@CRLF&@CRLF&":"&$thestr[$i]
Next
;ConsoleWrite($thelast&@CRLF)
FileDelete("a.txt")
FileWrite("a.txt",$thelast)
$diff=TimerDiff($begin)
MsgBox(0,"",$diff&"毫秒")
如果保证文件格式规范,可以不用UBOUND,再精简一点,但代码还是感觉冗余啊,。。唉,还是学习学习前面几位耗了。。 |