0

我正在做一个学校项目,我们正在学习如何阅读和搜索文本文件。你能帮我理解下面的代码吗?我知道第一部分要求用户输入他们想要搜索的团队名称,并将其存储为变量,然后打开文件。但是,我不明白粗体代码(在星星之间)。如果有人可以解释粗体代码的每一行(在星号之间),那将会很有帮助。提前致谢。

Console.Write("Enter the team name:")
                findname = Console.ReadLine()
                FileOpen(1, "TeamdataFile.txt", OpenMode.Input)

                **Do
                    Input(1, teamname)
                    Input(1, townname)
                    Input(1, coachname)
                    Input(1, phone)
                    If teamname.ToLower = findname.ToLower Then
                        Console.WriteLine("Team: {0}, from {1}, coach: {2}, contact: {3}", teamname, townname, coachname, phone)
                        foundresult = True
                    End If
                Loop Until EOF(1)**
                FileClose(1)
4

1 回答 1

3

我希望这可能会有所帮助(我已经评论了您需要的所有这些行):

**Do  ' start the loop
    Input(1, teamname)  ' read the data record from file and store it into variable teamname
    Input(1, townname)  ' read the data record from file and store it into variable townname
    Input(1, coachname)  ' read the data record from file and store it into variable coachname
    Input(1, phone)  ' read the data record from file and store it into variable phonename
    If teamname.ToLower = findname.ToLower Then  ' if findname equals teamname
        Console.WriteLine("Team: {0}, from {1}, coach: {2}, contact: {3}", teamname, townname, coachname, phone)  ' write something on the console
        foundresult = True  ' set some boolean variable to true
    End If
Loop Until EOF(1)**  ' continue the loop until you read the entire file
于 2013-06-09T14:19:47.737 回答