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