|
本帖最后由 wongfung 于 2009-4-30 13:50 编辑
我想將這個文件
-----------------
id="1"
aaa
bbb
id="12"
aaa
bbb
id="123"
aaa
bbb
-----------------
變成
-----------------
001Line1
001Line2
012Line1
012Line2
123Line1
123Line2
-----------------
於是寫了以下代碼:
#Include <File.au3>
#include <Array.au3>
$file = FileOpenDialog("Open", @WorkingDir, "All Files(*.*)" , 1 )
FileCopy($file, $file & "_converted", 1)
Local $aLine, $id
_FileReadToArray($file & "_converted", $aLine)
$i = 1
While $i < UBound($aLine)
If Stringleft($aLine[$i], 4) = 'id="' Then
$id = StringTrimRight ( $aLine[$i], 1 )
$id = StringMid($id, 5)
$id = StringRight("000" & $id, 3)
$line1 = StringReplace($aLine[$i+1], "aaa", $id & "Line1" )
$line2 = StringReplace($aLine[$i+2], "bbb", $id & "Line2" )
_ArrayDelete($aLine, $i)
Else
$i += 2
EndIf
WEnd
_FileWriteFromArray($file & "_converted", $aLine, 1)
MsgBox( 0, "", "OK")
結果只有id那行給刪掉, 但aaa跟bbb沒有給replace...
請問如何解決???
代碼應如何改寫??? |
|