StringWriter StringReader
The string type in C# serves as a representation of a sequence of Unicode characters, and it can contain zero or more characters. It's worth noting that the lowercase "string" is an alias for the "String" class within the .NET Framework.
The StringWriter class is designed to implement a TextWriter, which facilitates writing information to a string. This class stores the information in an underlying StringBuilder, which provides efficient string manipulation capabilities.
The WriteLine(String) method, belonging to the StringWriter (and also available in other TextWriter implementations), writes a specified string to the text stream and appends a line terminator. This method is useful for formatting output when writing to a string.
StringReader.ReadLine method
On the other hand, the StringReader class implements a TextReader specifically designed for reading from a string. It allows you to read characters and strings from the underlying string in a sequential manner.
The StringReader.ReadLine method, present in the StringReader class, reads a single line from the underlying string, up to the point where it encounters a line terminator. This method is commonly used to read and process text line by line when working with string input.
The following program shows how to use StringWriter and StringReader Classes in C#.
Full Source C#Conclusion
These classes and methods provide convenient functionalities for working with strings, enabling efficient reading and writing operations when interacting with text-based data.
- How to use C# string Clone
- How to use C# string Compare
- How to use C# string Concat
- How to use C# string Contains
- How to use C# string Copy
- How to use C# string CopyTo
- How to use C# string EndsWith
- How to use C# string Equals
- How to use C# string Format
- How to use C# string IndexOf
- How to use C# string Insert
- How to use C# string Length
- How to use C# string Split
- Substring in C#
- How to validate a string using TryParse in C#
- How to C# String Null
- Generate random strings, alphanumeric strings and numbers