【发布时间】:2016-04-13 17:27:52
【问题描述】:
现在我正在阅读 .txt 文件中的一些行。 比方说,用户输入他的姓名并在 .txt 中保存“在 2016 年 13 月 4 日上午 10:55 登录 {username}”。 (只是一个例子。)
现在我想阅读 .txt 并将特定部分仅打印到文本框中。 意思是,在文本框中应出现“{Username} - 13/04/2016 - 10:55 am”。
到目前为止,我能够从 .txt 中读取并打印整行。
private void button_print_results_Click(object sender, RoutedEventArgs e)
{
int counter = 0;
string actual_line;
System.IO.StreamReader file_to_read =
new System.IO.StreamReader("myText.txt");
while ((actual_line = file_to_read.ReadLine()) != null)
{
textBox_results.Text = textBox_results.Text +"\n"+ actual_line;
counter++;
}
file_to_read.Close();
}
有没有办法在不覆盖整个文件的情况下实现这一点?
不,我无法更改名称等的保存格式。 (我在这里使用它们是为了更好地理解,我需要阅读/检查的实际行是不同的并且是自动生成的)。
我不希望有完整的工作代码,如果您能告诉我需要查看哪些命令,那就太好了。自从我上次使用 c#/wpf 以来已经很长时间了,而且我从来没有使用过 Streamreader...
谢谢
【问题讨论】:
标签: c# .net wpf streamreader