VB 如何根据用户选择从文本文件中调用一行文本?

VB How do i recall a line of text from a text file, based on user selection?

这是我目前所拥有的...

    Dim Test As String = "C:\test.txt"
    Dim User As String


    Console.WriteLine("What user password would you like?")
    User = Console.ReadLine().ToLower
    Dim objReader As New System.IO.StreamReader(Test)

    While Not objReader.EndOfStream

        If User.Contains("Admin1") Then


            Console.WriteLine(objReader.ReadLine())

        End If
    End While

    objReader.Close()

我不确定“(objReader.ReadLine()”的括号中是否需要添加一些内容,如果有人能提供帮助,那就太好了,谢谢。

这就是你想要的...

Using sr As New StreamReader("C:\test.txt")
    Dim Line As String = sr.ReadLine()
    While Line IsNot Nothing
        If Line.Contains("Admin1") Then
            Console.WriteLine(Line)
        End If
        Line = sr.ReadLine()
    End While
End Using

"Using" 块确保 StreamReader 对象自动关闭和释放,无需您担心。