Read line by line from StringReader - CSharp File IO

CSharp examples for File IO:String Reader Writer

Description

Read line by line from StringReader

Demo Code


using System;/*from  w w w.j  av  a 2  s .c o m*/
using System.IO;
using System.Text;

public class Program
{
    public static void Main(string[] args)
    {
        StringReader reader2 = new StringReader("asdfthis is a test\nthis is a test\ns");
        string firstLine = reader2.ReadLine();
        Console.WriteLine("\nFirst line read from a reader initialized from the previous StringBuilder:\n{0}", firstLine);

        string rest = reader2.ReadToEnd();

        Console.WriteLine("\nReading the rest of the StringReader:");
        foreach (string lineRead in rest.Split(new char[] { '\n' }))
        {
            Console.WriteLine(lineRead);
        }
    }
}

Result


Related Tutorials