Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/loops/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Vb.net 移动到StreamReader中的下一行_Vb.net_Loops_Streamreader_Readline - Fatal编程技术网

Vb.net 移动到StreamReader中的下一行

Vb.net 移动到StreamReader中的下一行,vb.net,loops,streamreader,readline,Vb.net,Loops,Streamreader,Readline,在循环中是否可以移动到下一行或临时读取下一行?我没有太多的运气找到任何有用的数据,如何做到这一点,我的猜测是不知何故找到行号(索引)你目前在哪一行,然后读取+1从你所在的位置 Using TestFile As New IO.StreamReader(My.Settings.cfgPath & "tempRPT.txt", System.Text.Encoding.Default, False, 4096) Do Until TestFile.EndOfStream

在循环中是否可以移动到下一行或临时读取下一行?我没有太多的运气找到任何有用的数据,如何做到这一点,我的猜测是不知何故找到行号(索引)你目前在哪一行,然后读取+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
使用TestFile作为新的IO.StreamReader(My.Settings.cfgPath&“temrpt.txt”,System.Text.Encoding.Default,False,4096)
直到TestFile.EndOfStream为止
ScriptLine=TestFile.ReadLine
ScriptLine=LCase(ScriptLine)
如果InStr(脚本行,“更新:[b”),则
Dim m As Match=Regex.Match(脚本行“\([^)]*)\)”)
建筑商附录线(m.值)
'这是它将临时移动到下一行以从中读取的位置
如果InStr(脚本行,“hive:write:”)>0或InStr(脚本行,“update:[b”)>0 Then’和InStr(脚本行,“setmarkerposlocal.sqf”)<1则
builder.AppendLine(脚本行)
如果结束
如果结束
环
终端使用

假设您没有使用旧版本的.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

假设您没有使用旧版本的.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

试试这个。实数所有行,并将它们放入一个
队列(共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
Dim路径为String=My.Settings.cfgPath&“tempRPT.txt”
将行的大小调整为String()=IO.File.ReadAllLines(路径,System.Text.Encoding.Default)
Dim que=新队列(字符串)(行)
当que.Count>0时执行此操作
ScriptLine=que.Dequeue()
ScriptLine=LCase(ScriptLine)
如果InStr(脚本行,“更新:[b”),则
Dim m As Match=Regex.Match(脚本行“\([^)]*)\)”)
建筑商附录线(m.值)
将下一行变暗为String=que。Peek“临时读取下一行”这是它将临时移动到下一行以从中读取的位置
如果InStr(下一行,“hive:write:”)>0或InStr(下一行,“update:[b”)>0 Then”和InStr(下一行,“setmarkerposlocal.sqf”)<1则
builder.AppendLine(下一行)
如果结束
如果结束
环

试试这个。实数所有行,并将它们放入一个
队列(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
Dim路径为String=My.Settings.cfgPath&“tempRPT.txt”
将行的大小调整为String()=IO.File.ReadAllLines(路径,System.Text.Encoding.Default)
Dim que=新队列(字符串)(行)
当que.Count>0时执行此操作
ScriptLine=que.Dequeue()
ScriptLine=LCase(ScriptLine)
如果InStr(脚本行,“更新:[b”),则
Dim m As Match=Regex.Match(脚本行“\([^)]*)\)”)
建筑商附录线(m.值)
将下一行变暗为String=que。Peek“临时读取下一行”这是它将临时移动到下一行以从中读取的位置
如果InStr(下一行,“hive:write:”)>0或InStr(下一行,“update:[b”)>0 Then”和InStr(下一行,“setmarkerposlocal.sqf”)<1则
builder.AppendLine(下一行)
如果结束
如果结束
环

您可以使用
System.IO.file.ReadAllLines()读取内存中的整个文件。
您可以使用
System.IO.file.ReadAllLines()读取内存中的整个文件
。请确保不要在空集合中查看
Peek
。这和NoAlias的答案都很好。我将首先尝试这一个,看看它是如何工作的。我很感激:)最后我使用了你的答案。谢谢你的答案!确保不要在空集合中查看
Peek
。这和NoAlias的答案都是正确的吃一个。我要先试试这个,看看它是怎么工作的。我很感激:)最后我用了你的。谢谢你的回答!