Loop through the lines of a text file in VB.NET

后端 未结 3 1985
猫巷女王i
猫巷女王i 2020-12-19 21:37

I have a text file with some lines of text in it.

I want to loop through each line until an item that I want is found*, then display it on the screen, in the form of

3条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-19 22:07

    You can use the File.ReadLines Method in order to iterate throughout your file, one line at a time. Here is a simple example:

        Dim Term As String = "Your term"
        For Each Line As String In File.ReadLines("Your file path")
            If Line.Contains(Term) = True Then
                ' Do something...Print the line
                Exit For
            End If
        Next
    

提交回复
热议问题