Streamreader extensions (C#)
OK. These two extension functions are very practical to me: omitting lines, and copying lines from one stream to another. Although it is very simple to implement it every time in code, I suggest using those extensions to be more productive!
public static class StreamReaderExtensions
{
/// <summary>
/// Jumps the number of lines that is specified.
/// </summary>
/// <param name="reader">The reader object.</param>
/// <param name="count">The number of lines to jump.</param>
public static void OmitLines(this StreamReader reader, int count)
{
for (int iLine = 0; iLine < count; iLine++) reader.ReadLine();
}
public static void CopyLinesTo(this StreamReader source,StreamWriter target, int count)
{
for (int iLine = 0; iLine < count; iLine++) target.WriteLine(source.ReadLine());
}
}
Comments