简体   繁体   English

逐行遍历文本文件c#

[英]Iterate through a text file line by line c#

Basically this is the code I currently have; 基本上这是我目前拥有的代码;

public async void readTextFile()
{      
    try {
        StorageFolder folder = KnownFolders.VideosLibrary;
        StorageFile storageFile = await folder.GetFileAsync("students.txt");

        string text = await Windows.Storage.FileIO.ReadTextAsync(storageFile);

        } catch (Exception e) {
            the_name.Text = "{0} Exception caught." + e;
        }
    }
}

The text file has a list of students that is laid out like this 文本文件具有这样排列的学生列表

Student Name|false 学生姓名|假

Student Second|false 学生第二|假

With the names of 10 students and the word false to specify whether they've taken the test in the app, if they have taken it false reverts to true. 如果有10名学生的名字和单词false,以指定他们是否已在应用程序中参加考试,如果他们接受了false,则会还原为true。

What my question is. 我的问题是什么。 How can I iterate through every line in that text file and store the one that has been typed in the textbox in a variable? 如何遍历该文本文件中的每一行,并将在文本框中键入的内容存储在变量中?

Just to note: I'm creating a windows desktop store application 请注意:我正在创建Windows桌面商店应用程序

Thanks in advance! 提前致谢!

代替使用ReadTextAsync方法,可以使用ReadLinesAsync方法,然后遍历结果并分割管道字符以查找所需内容。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM