Use StringWriter to write string : StringWriter « File Stream « C# / C Sharp






Use StringWriter to write string

 

using System;
using System.IO;
using System.Text;
class StringReadWriteApp {
    static void Main(string[] args) {
        StringWriter w = new StringWriter();
        w.WriteLine("Sing a song of {0} pence", 6);
        string s = "A pocket full of rye";
        w.Write(s);
        w.Write(w.NewLine);
        w.Write(String.Format(4 + " and " + 20 + " blackbirds"));
        w.Write(new StringBuilder(" baked in a pie"));
        w.WriteLine();
        w.Close();
        Console.WriteLine(w);
    }
}
           
         
  








Related examples in the same category

1.The hex dump program.
2.StringWriter implements a TextWriter for writing information to a string. The information is stored in an underlying StringBuilder.
3.Initializes a new instance of the StringWriter class with the specified format control.
4.Initializes a new instance of the StringWriter class that writes to the specified StringBuilder.
5.Initializes a new instance of the StringWriter class.