illustrates reading and writing string data : StringBuilder « Development Class « C# / C Sharp






illustrates reading and writing string data

illustrates reading and writing string data
 
/*
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();

  }

}



           
         
  








Related examples in the same category

1.Create a StringBuilder which hold 100 characters.
2.Length and Indexer
3.Use StringBuilder to reverse a string
4.using the StringBuilder methods Replace, Insert, Append, AppendFormat, and Remove:
5.String ConcatenationString Concatenation
6.Replace char in a StringBuilder object
7.Replace Char with String
8.Represents a mutable string of characters.
9.Create StringBuilder class using the specified capacity.
10.Create StringBuilder class that starts with a specified capacity and can grow to a specified maximum.
11.Create a StringBuilder class using the specified string.
12.Create StringBuilder class using the specified string and capacity.
13.Create StringBuilder class from the specified substring and capacity.
14.Appends various data to StringBuilder
15.Appends a composite format string
16.Appends the default line terminator to the end of the current StringBuilder object.
17.Gets or sets the maximum number of characters that can be contained
18.Removes all characters from the current StringBuilder instance.
19.Copies characters to a destination Char array.
20.Inserts various data types
21.Removes the specified range of characters from this instance.
22.Replaces all occurrences of a specified character in this instance with another specified character.