C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML
C# StringWriter ClassThis class is used to write and deal with string data rather than files. It is derived class of TextWriter class. The string data written by StringWriter class is stored into StringBuilder. The purpose of this class is to manipulate string and save result into the StringBuilder. StringWriter Class Signature[SerializableAttribute] [ComVisibleAttribute(true)] public class StringWriter : TextWriter C# StringWriter Constructors
C# StringWriter Properties
C# StringWriter Methods
C# StringWriter ExampleIn the following program, we are using StringWriter class to write string information to the StringBuilder class. The StringReader class is used to read written information to the StringBuilder.
using System;
using System.IO;
using System.Text;
namespace CSharpProgram
{
class Program
{
static void Main(string[] args)
{
string text = "Hello, Welcome to the TheDeveloperBlog \n" +
"It is nice site. \n" +
"It provides technical tutorials";
// Creating StringBuilder instance
StringBuilder sb = new StringBuilder();
// Passing StringBuilder instance into StringWriter
StringWriter writer = new StringWriter(sb);
// Writing data using StringWriter
writer.WriteLine(text);
writer.Flush();
// Closing writer connection
writer.Close();
// Creating StringReader instance and passing StringBuilder
StringReader reader = new StringReader(sb.ToString());
// Reading data
while (reader.Peek() > -1)
{
Console.WriteLine(reader.ReadLine());
}
}
}
}
Output: Hello, Welcome to the TheDeveloperBlog It is nice site. It provides technical tutorials
Next TopicC# StringReader
|