StringWriter and StringReader
The StringWriter class in .NET Framework serves as a TextWriter implementation that enables writing information to a string. It internally utilizes the StringBuilder class to store the written information. The StringBuilder class, on the other hand, represents a mutable string of characters and cannot be inherited.
StringWriter class
By using the StringWriter class, developers can easily write data to a string in a convenient and efficient manner. The written information is automatically stored in the underlying StringBuilder object, allowing for easy retrieval and manipulation.
The WriteLine(String) method, available in StringWriter, is used to write a string followed by a line terminator to the text stream. This method appends the specified string to the internal StringBuilder object and appends a line terminator character sequence to mark the end of the line.
StringReader class
On the other hand, the StringReader class implements a TextReader that allows reading from a string. It provides functionality to read character data sequentially from the underlying string source.
The ReadLine method in StringReader is used to read a line of text from the underlying string. It reads characters until it encounters a line terminator sequence or reaches the end of the string.
The following program shows how to use StringWriter and StringReader Classes in VB.NET.
Full Source VB.NETConclusion
Using the StringWriter and StringReader classes, developers can efficiently write and read string data. This is particularly useful when working with string-based operations and when there is a need to manipulate or process string content in memory without directly interacting with external files or streams.
- How to vb.net String Length()
- How to vb.net String Insert()
- How to vb.net String IndexOf()
- How to vb.net String Format()
- How to vb.net String Equals()
- How to vb.net String CopyTo()
- How to vb.net String Copy()
- How to vb.net String Contains()
- How to vb.net String Compare()
- How to vb.net String Clone()
- How to vb.net String Chars()
- How to vb.net String substring()
- How to vb.net String Split()
- How to vb.net String EndsWith()
- How to vb.net String Concat()
- How to VB.NET String Null