Read string from StringReader - CSharp File IO

CSharp examples for File IO:String Reader Writer

Description

Read string from StringReader

Demo Code


using System;/*w ww. j  a  v a2  s.co m*/
using System.IO;
using System.Text;

public class Program
{
    public static void Main(string[] args)
    {
        string input = "this is a test";
        Console.WriteLine("Original text:\n{0}", input);

        StringReader reader = new StringReader(input);
        StringWriter writer = new StringWriter();

        char[] buffer = new char[] { 'a'};

        writer.Write(buffer);

        const char SPACE = ' ';

        char ch = (char)reader.Read();
        string bigGulp = reader.ReadToEnd();
        Console.WriteLine("\nReading all the rest:\n{0}", bigGulp);

        writer.Write(bigGulp);
        Console.WriteLine("StringWriter now contains:\n{0}", writer.ToString());


    }
}

Related Tutorials