vb删除txt中的多余的文本
文本内容如下所示:
INPUT 11
NAME "" LABEL 0.00 0.00
LINK 17 Q 545.000 COMPOSITION 1
TIME FROM 600.0 UNTIL 1200.0
INPUT 12
NAME "" LABEL 0.00 0.00
LINK 18 Q 352.000 COMPOSITION 2
TIME FROM 600.0 UNTIL 1200.0
INPUT
NAME "" LABEL 0.00 0.00
LINK Q COMPOSITION
TIME FROM UNTIL
INPUT
NAME "" LABEL 0.00 0.00
LINK Q COMPOSITION
TIME FROM UNTIL
INPUT
NAME "" LABEL 0.00 0.00
LINK Q COMPOSITION
TIME FROM UNTIL
想把INPUT 12
NAME "" LABEL 0.00 0.00
LINK 18 Q 352.000 COMPOSITION 2
TIME FROM 600.0 UNTIL 1200.0
该段之后的3段,INPUT
NAME "" LABEL 0.00 0.00
LINK Q COMPOSITION
TIME FROM UNTIL
删除,请指点给出代码,万分感谢,,!
Private Sub Command1_Click()
Dim strLine As String, strTemp As String
Open "c:\test\a.txt" For Input As #1
Open "c:\test\temp.txt" For Output As #2
Do Until EOF(1)
Line Input #1, strLine
If Left(Trim(strLine), Len(strPatern)) = strPatern Then
Do While Left(Trim(strLine), Len(strBlockHeader)) <> strBlockHeader
Print #2, strLine
Line Input #1, strLine
Loop
GoTo ExitSub
End If
Print #2, strLine
Loop
ExitSub:
Close #2
Close #1
Kill "c:\test\a.txt"
Name "c:\test\temp.txt" As "c:\test\a.txt"
End Sub
[解决办法]
哦,代码中的 strTemp 并没有用到。原来是为更复杂的情况预备的。