/*
Mastering Visual C# .NET
by Jason Price, Mike Gunderloy
Publisher: Sybex;
ISBN: 0782129110
*/
/*
Example15_17.cs illustrates reading and writing string data
*/
using System;
using System.IO;
using System.Text;
public class Example15_17
{
public static void Main()
{
// create a new string to work with
StringBuilder sb = new StringBuilder();
// use a StringWriter to write data to the string
StringWriter sw = new StringWriter(sb);
// write some text to the string
sw.Write("This is a test of the StringWriter class");
sw.Close();
// now open the string for reading
StringReader sr = new StringReader(sb.ToString());
// read the entire string into a buffer and display it
string EntireString;
EntireString = sr.ReadToEnd();
Console.WriteLine(EntireString);
// clean up
sr.Close();
}
}
|