haodd 发表于 2010-8-5 22:21:43

【已解决】筛选问题

本帖最后由 haodd 于 2010-8-5 22:59 编辑

文本文件 xx.txt
为如下内容
2010-08-04 12:58:31 :AVcc12
2010-08-04 12:58:34 :AVcc13
2010-08-04 13:03:30 :AVcc14
2010-08-04 13:13:43 :AVcc15
2010-08-04 13:34:52 :AVcc16
2010-08-04 13:41:25 :AVcc17
2010-08-04 13:54:44 :AAcc1
2010-08-04 14:08:19 :AAcc9
2010-08-04 14:09:01 :AAcc1
2010-08-04 14:15:27 :AVcc7
2010-08-04 14:16:38 :AVcc6
2010-08-04 14:21:39 :AVcc13
2010-08-04 14:22:24 :AVcc14
2010-08-03 12:44:16 :AVcc15
2010-08-04 14:31:59 :AVcc16
2010-08-04 14:40:54 :AVcc17
2010-08-04 14:42:49 :AVcc18
2010-08-04 16:04:30 :AVcc19
2010-08-04 16:18:51 :AAcc9

怎么得到
筛选后的内容
怎么做比较高效
2010-08-04 12:58:31 :AVcc12
2010-08-04 12:58:34 :AVcc13
2010-08-04 13:03:30 :AVcc14
2010-08-04 13:13:43 :AVcc15
2010-08-04 13:34:52 :AVcc16
2010-08-04 13:41:25 :AVcc17
2010-08-04 13:54:44 :AAcc1
2010-08-04 14:08:19 :AAcc9
2010-08-04 14:15:27 :AVcc7
2010-08-04 14:16:38 :AVcc6
2010-08-04 14:42:49 :AVcc18
2010-08-04 16:04:30 :AVcc19

afan 发表于 2010-8-5 22:49:36

Local $Str = FileRead('xx.txt')
Local $sR = StringRegExp($Str, '(.+\:(.+))[\r|$]', 3), $out
For $i = 1 To UBound($sR) - 1 Step 2
        If IsDeclared('_' & $sR[$i]) Then ContinueLoop
        $out &= $sR[$i - 1] & @CRLF
        Assign('_' & $sR[$i], 0)
Next
FileWrite('new.txt', $out)

afan 发表于 2010-8-5 22:52:21

再上一段测试效率的代码,完成不超过1毫秒Local $Str = _
                '2010-08-04 12:58:31 :AVcc12' & @CRLF & _
                '2010-08-04 12:58:34 :AVcc13' & @CRLF & _
                '2010-08-04 13:03:30 :AVcc14' & @CRLF & _
                '2010-08-04 13:13:43 :AVcc15' & @CRLF & _
                '2010-08-04 13:34:52 :AVcc16' & @CRLF & _
                '2010-08-04 13:41:25 :AVcc17' & @CRLF & _
                '2010-08-04 13:54:44 :AAcc1' & @CRLF & _
                '2010-08-04 14:08:19 :AAcc9' & @CRLF & _
                '2010-08-04 14:09:01 :AAcc1' & @CRLF & _
                '2010-08-04 14:15:27 :AVcc7' & @CRLF & _
                '2010-08-04 14:16:38 :AVcc6' & @CRLF & _
                '2010-08-04 14:21:39 :AVcc13' & @CRLF & _
                '2010-08-04 14:22:24 :AVcc14' & @CRLF & _
                '2010-08-03 12:44:16 :AVcc15' & @CRLF & _
                '2010-08-04 14:31:59 :AVcc16' & @CRLF & _
                '2010-08-04 14:40:54 :AVcc17' & @CRLF & _
                '2010-08-04 14:42:49 :AVcc18' & @CRLF & _
                '2010-08-04 16:04:30 :AVcc19' & @CRLF & _
                '2010-08-04 16:18:51 :AAcc9'

Local $ts = TimerInit()
Local $sR = StringRegExp($Str, '(.+\:(.+))[\r|$]', 3), $out
For $i = 1 To UBound($sR) - 1 Step 2
        If IsDeclared('_' & $sR[$i]) Then ContinueLoop
        $out &= $sR[$i - 1] & @CRLF
        Assign('_' & $sR[$i], 0)
Next
MsgBox(0, '耗时(ms):' & TimerDiff($ts), $out)

haodd 发表于 2010-8-5 22:58:27

正解 谢谢!
页: [1]
查看完整版本: 【已解决】筛选问题