Skip to content

Instantly share code, notes, and snippets.

@hagbarddenstore
Last active December 31, 2015 14:49
Show Gist options
  • Save hagbarddenstore/8002441 to your computer and use it in GitHub Desktop.
Save hagbarddenstore/8002441 to your computer and use it in GitHub Desktop.
// Variant 1
var lines = File.ReadAllLines("in.txt");
var output = new StringBuilder();
foreach (var line in lines)
{
if (ShouldUseThisLine(line))
{
output.AppendLine(line);
}
}
File.WriteAllText("out.txt", output.ToString());
// Variant 2
string line;
using (var writer = new StreamWriter("out.txt"))
{
using (var reader = new StreamReader("in.txt"))
{
while ((line = reader.ReadLine()) != null)
{
if (ShouldUseThisLine(line))
{
writer.WriteLine(line);
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment