In this code string x gives an OutOfMemoryException. Is there any other way that I can parse all the files without getting OutofMemoryException? There seems to be nothing wrong in the code I have tried.
Someone suggested to make the program read file by file rather than reading whole files and putting it in one string x.
IEnumerable<string> textLines = Directory.GetFiles(@"C:\Users\karansha\Desktop\Unique_Express\", "*.*")
.Select(filePath => File.ReadLines(filePath))
.SelectMany(line => line);
string x = string.Join(",", textLines);
List<string> users = new List<string>();
Regex regex = new Regex(@"User:\s*(?<username>.*?)\s");
MatchCollection matches = regex.Matches(x);
foreach (Match match in matches)
{
var user = match.Groups["username"].Value;
if (!users.Contains(user)) users.Add(user);
}
int numberOfUsers = users.Count(name => name.Length < 15);
Console.WriteLine("Unique_Users_Express=" + numberOfUsers);