Reading large text files with C# and Visual Studio 2008
I managed to read text file with 200 000 lines within 4 seconds.
on Pentium 4 2.4GHZ with 500MB of RAM (Virtual Machine)
// this code assumes the following using statements
// using System.IO;
// using System.Text.RegularExpressions;
StreamReader sr = new StreamReader(openFileDialog1.FileName);
string[] arr = Regex.Split(sr.ReadToEnd(), @"\r\n");
sr.Close();
foreach(string s in arr) {
if (s.Contains("SOMEWORD"))
{
tbLog.AppendText(s.Trim() + Environment.NewLine);
}
}
Source:
http://www.dotnet2themax.com/ShowContent.aspx?ID=4ee44d6c-79a9-466d-ab47-56bba526534f