< Prev
Next >

C# StringReader

In our last tutorial, we have explained how you to use the StringWriter class, which is used to write characters to a string of type StringBuilder, which was automatically created by the StringWriter class.

Let us discuss the counterpart of StringWriter class i.e. StringReader class, which allows us to read the characters from a string of type StringBuilder, which was written to by the StringWriter class.

The StringReader class implements the TextReader abstract class and it is defined in the System.IO namespace.

Some commonly used constructors of StringReader

Constructors Description
FileStream(String string)
The constructor created an object of the StringReader that reads from the specified String object.

Some commonly used write methods of StringReader

Methods Description
int Read()
This method reads the next character from the input string as an Int32 object, or -1 if no more characters are available.

int Read(char[] array, int index, int total)
This method reads a character array from the input string, where:
  • index, represents the starting index in the char array to begin writing at.
  • total, represents the total number of characters read from input string and write to the char array.
This method returns the number of characters that have been read from the input string.

String ReadLine()
This method reads a line of characters from the input string and returns the data as a String, or null if the end of the input stream is reached.

void Close()
This method closes the StringReader.

Please Subscribe

Please subscribe to our social media channels for daily updates.

Decodejava Facebook Page  DecodeJava Twitter Page Decodejava Google+ Page



Please check our latest addition