我需要我在實習中建立的程序的幫助。 這個想法是檢查用戶在任何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