比如有个TXT文件里的内容是这样的:
aa=1
bb=2
cc=3
dd=4
.
.
.
ee=565
ff=545
dd=22
.
ee=23423
.
现在想获取所有从“dd=”开始到"ee="的所有行内容,有一个关键的问题就是,无法确定这些内容到底从第几行开始,然后从第几行结束。

解决方案 »

  1.   

    这里有一段代码,我自己写的,应该说基本满足,但效率不敢说,代码也没有优化
    Dim sy As String
    Private Sub Command1_Click()
    Command1.Enabled = False
    Do Until 0 > 1
    Do
    If Not EOF(1) Then
    Line Input #1, sy
    Else
    Command1.Enabled = True
    Close #1
    Exit Sub
    Command1.Enabled = True
    End If
    Loop Until Left(sy, 2) = "dd"
    Text1.Text = Text1.Text & sy & vbCrLf
    Do
    If Not EOF(1) Then
    Line Input #1, sy
    Text1.Text = Text1.Text & sy & vbCrLf
    Else
    Close #1
    Exit Sub
    Command1.Enabled = True
    End If
    Loop Until Left(sy, 2) = "ee"
    Loop
    End SubPrivate Sub Command2_Click()
    Open App.Path & "\shiyan.txt" For Input As #1
    Text1.Text = Text1.Text & "打开成功!" & vbCrLf
    End Sub下面是试验文件
    aa=1 
    bb=2 
    cc=3 
    dd=4 
    hh=6
    ss=89
    df=89
    ee=565 
    ff=545 
    dd=22 
    sd=45
    ee=23423 
      

  2.   

        Dim temp As String
        Text1.Text = ""
        Open "F:\qqq.txt" For Input As #1
        Do While Not EOF(1)
            Line Input #1, temp
            If InStr(temp, "dd=") <> 0 Then
                Text1.Text = Text1.Text & temp & vbCrLf
                Line Input #1, temp
                Text1.Text = Text1.Text & temp & vbCrLf
            ElseIf InStr(temp, "ee=") <> 0 Then
                Text1.Text = Text1.Text & temp & vbCrLf
            End If
        Loop
        Close #1测试内容:
    aa=1 
    bb=2 
    cc=3 
    dd=4 
    hh=6 
    ss=89 
    df=89 
    ee=565 
    ff=545 
    dd=22 
    sd=45 
    ee=23423
    aa=11 
    bb=2 1
    cc=3 1
    dd=4 1
    hh=6 1
    ss=89 1
    df=89 1
    ee=565 1
    ff=545 1
    sd=45 1