我需要我在实习中建立的程序的帮助。 这个想法是检查用户在任何PC上登录的频率。 当用户登录时,该信息将记录在文本文件中,如此格式。C#搜索文本文件,返回包含单词的所有行
01-01-2011 16:47:10-002481C218B0-WS3092-Chsbe (XP-D790PRO1)
现在我需要搜索文本文件和(例如)搜索用户Chsbe的所有登录日期的文本文件。
到目前为止我的代码:
private void btnZoek_Click(object sender, EventArgs e)
{
int counter = 0; string line;
// Read the file and display it line by line.
System.IO.StreamReader file = new System.IO.StreamReader("c:\\log.txt");
while((line = file.ReadLine()) != null)
{ if (line.Contains(txtZoek.Text))
{
txtResult.Text = line.ToString();
}
}
file.Close();
}
我的问题是,我该如何返回一个包含搜索关键词,以txtResult日志中的所有字符串?
直视正则表达式 – 2012-04-12 09:16:39
难道possbile获得源为XML? 否则如前所述看看正则表达式。 如果搜索变得更复杂看看某种全文搜索组件 – 2012-04-12 09:18:09