1

ループ内で次の行に移動するか、次の行を一時的に読み取ることは可能ですか? これを行う方法に関する有用なデータを見つけるのはあまり運がありませんでした。私の推測では、現在の行の行番号 (インデックス) を見つけて、現在の場所から +1 を読み取ります。

Using TestFile As New IO.StreamReader(My.Settings.cfgPath & "tempRPT.txt", System.Text.Encoding.Default, False, 4096)
        Do Until TestFile.EndOfStream
            ScriptLine = TestFile.ReadLine
            ScriptLine = LCase(ScriptLine)
            If InStr(ScriptLine, "update: [b") Then
                Dim m As Match = Regex.Match(ScriptLine, "\(([^)]*)\)")
                builder.AppendLine(m.Value)

                'This is where it would move to next line temporarily to read from it
                If InStr(ScriptLine, "hive: write:") > 0 Or InStr(ScriptLine, "update: [b") > 0 Then 'And InStr(ScriptLine, "setmarkerposlocal.sqf") < 1 Then
                   builder.AppendLine(ScriptLine)

                End If
            End If

        Loop
    End Using
4

2 に答える 2

3

これを試して。すべての線をリアルにして、Queue(Of T)オブジェクトに入れます。

    Dim path As String = My.Settings.cfgPath & "tempRPT.txt"

    Dim lines As String() = IO.File.ReadAllLines(path, System.Text.Encoding.Default)
    Dim que = New Queue(Of String)(lines)

    Do While que.Count > 0
        ScriptLine = que.Dequeue()
        ScriptLine = LCase(ScriptLine)
        If InStr(ScriptLine, "update: [b") Then
            Dim m As Match = Regex.Match(ScriptLine, "\(([^)]*)\)")
            builder.AppendLine(m.Value)

            Dim next_line As String = que.Peek      'Read next line temporarily                'This is where it would move to next line temporarily to read from it
            If InStr(next_line, "hive: write:") > 0 Or InStr(next_line, "update: [b") > 0 Then 'And InStr(next_line, "setmarkerposlocal.sqf") < 1 Then
                builder.AppendLine(next_line)
            End If
        End If
    Loop
于 2012-07-31T15:02:40.007 に答える
1

古いバージョンの .Net を使用していないと仮定すると、文字列のリストを使用する方が簡単な場合があります。

Dim lstLinesInTextFile As List(of String) = IO.File.ReadAllLines(My.Settings.cfgPath & "tempRPT.txt").ToList()

        Dim intCursor As Integer = 0
        For Each strLine As String In lstLinesInTextFile

            'Perform Logic Here

            'To View Next Line:
            If lstLinesInTextFile.Count > intCursor + 1 Then

                Dim strNextLine As String = lstLinesInTextFile(intCursor + 1)

                'Perform Logic Here.

            End If

            intCursor += 1

        Next
于 2012-07-31T15:00:30.213 に答える