找回密码
 加入
搜索
查看: 1339|回复: 3

文本處理問題:如何刪除一行

[复制链接]
发表于 2009-2-17 16:48:30 | 显示全部楼层 |阅读模式
各位前輩好,,有個問題請教
目前我有一個test.txt檔,內容大致如下
A
2
B
....
A3B4
另外有一個判別式, 用filereadline逐行判斷
例如
for $i = 1 to 99999
$line=fileReadLine($file,$i)
if $line<>數字 then 刪除行
next
舉例若想把不等於數字的行都刪除掉,最後使得test.txt變成
2
4
....
請問應該怎麼寫??
=====================
我目前的寫法是 if $line=數字 then
FileWriteLine($file2)
但是碰到一個問題,,
原始檔案非常大,如果判別$i超過66xxx就停止了
所以才有想判別若失敗, 就刪除行的概念..

[ 本帖最后由 hohooh 于 2009-2-18 15:17 编辑 ]
发表于 2009-2-17 17:10:51 | 显示全部楼层
$var = FileRead("test.txt")
$str = StringRegExp($var, "\n*\d+\r", 3)
Dim $result = ""
For $o = 0 to Ubound($str) - 1
        $result &= $str[$o]
Next
msgBox(0, '', $result)
发表于 2009-2-17 21:04:36 | 显示全部楼层
你的写法错误,FileWriteLine 是在文件末尾追加一行。


#include <Array.au3>
#include <File.au3>
Dim $aArray
        $var="C:\1.txt"
        _FileReadToArray($var, $aArray)

        For $i = 1 To $aArray[0]-1
                If StringIsDigit($aArray[$i])= 0 Then
                        _ArrayDelete($aArray[$i], 0)
                EndIf
        Next

        _FileWriteFromArray("C:\2.txt", $aArray)


[ 本帖最后由 Newbie 于 2009-2-17 21:11 编辑 ]
 楼主| 发表于 2009-2-18 15:16:46 | 显示全部楼层
Thanks Newbie~
It's OK!
您需要登录后才可以回帖 登录 | 加入

本版积分规则

QQ|手机版|小黑屋|AUTOIT CN ( 鲁ICP备19019924号-1 )谷歌 百度

GMT+8, 2024-5-5 06:27 , Processed in 0.071469 second(s), 20 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表