As title, I’m trying to replace 2 or more space between characters into a single space. The following code works, however, not for very large input file. How can I make it works for huge input file as well?
static void Main(string[] args)
{
Regex pattern = new Regex(@"[ ]{2,}"); //Pattern = 2 or more space in a string.
StreamReader reader = new StreamReader(@"C:\CSharpProject\in\abc.txt");
string content = reader.ReadToEnd();
reader.Close();
content = pattern.Replace(content, @" "); //Replace 2 or more space into a single space.
StreamWriter writer = new StreamWriter(@"C:\CSharpProject\out\abc.txt");
writer.Write(content);
writer.Close();
}
Line-by-line, like this: