StringReader Class

Implements a TextReader that reads from a string.

Syntax

Declaration

[Serializable]
[ComVisible(true)]
public class StringReader : TextReader, IDisposable

Inheritance Hierarchy

Inherited Members

System.IO.TextReader

, ,

System.Object

, , , , , ,

Constructors summary

Initializes a new instance of the StringReader class that reads from the specified string.

Methods summary

Releases the unmanaged resources used by the StringReader and optionally releases the managed resources.

Returns the next available character but does not consume it.

Reads the next character from the input string and advances the character position by one character.

Reads a block of characters from the input string and advances the character position by count.

Reads a specified maximum number of characters from the current string asynchronously and writes the data to a buffer, beginning at the specified index.

Reads a specified maximum number of characters from the current string asynchronously and writes the data to a buffer, beginning at the specified index.

Reads a line of characters from the current string and returns the data as a string.

Reads a line of characters asynchronously from the current string and returns the data as a string.

Reads all characters from the current position to the end of the string and returns them as a single string.

Reads all characters from the current position to the end of the string asynchronously and returns them as a single string.

Constructors

  • StringReader(String)

    Initializes a new instance of the StringReader class that reads from the specified string.

    public StringReader(string s)

    Parameters

    Exceptions

Methods

  • Dispose(Boolean)

    Releases the unmanaged resources used by the StringReader and optionally releases the managed resources.

    protected override void Dispose(bool disposing)

    Parameters

    • disposing

      true to release both managed and unmanaged resources; false to release only unmanaged resources.

    Overrides

  • Peek()

    Returns the next available character but does not consume it.

    public override int Peek()

    Returns

    • An integer representing the next character to be read, or -1 if no more characters are available or the stream does not support seeking.

    Exceptions

    Overrides

  • Read()

    Reads the next character from the input string and advances the character position by one character.

    public override int Read()

    Returns

    • The next character from the underlying string, or -1 if no more characters are available.

    Exceptions

    Overrides

  • Read(Char[], Int32, Int32)

    Reads a block of characters from the input string and advances the character position by count.

    public override int Read(char[] buffer, int index, int count)

    Parameters

    • buffer

      When this method returns, contains the specified character array with the values between index and (index + count - 1) replaced by the characters read from the current source.

    • index

      The starting index in the buffer.

    • count

      The number of characters to read.

    Returns

    • The total number of characters read into the buffer. This can be less than the number of characters requested if that many characters are not currently available, or zero if the end of the underlying string has been reached.

    Exceptions

    Overrides

  • ReadAsync(Char[], Int32, Int32)

    Reads a specified maximum number of characters from the current string asynchronously and writes the data to a buffer, beginning at the specified index.

    [ComVisible(false)]
    public override Task<int> ReadAsync(char[] buffer, int index, int count)

    Parameters

    • buffer

      When this method returns, contains the specified character array with the values between index and (index + count - 1) replaced by the characters read from the current source.

    • index

      The position in buffer at which to begin writing.

    • count

      The maximum number of characters to read. If the end of the string is reached before the specified number of characters is written into the buffer, the method returns.

    Returns

    • A task that represents the asynchronous read operation. The value of the TResult parameter contains the total number of bytes read into the buffer. The result value can be less than the number of bytes requested if the number of bytes currently available is less than the requested number, or it can be 0 (zero) if the end of the string has been reached.

    Exceptions

    Overrides

  • ReadBlockAsync(Char[], Int32, Int32)

    Reads a specified maximum number of characters from the current string asynchronously and writes the data to a buffer, beginning at the specified index.

    [ComVisible(false)]
    public override Task<int> ReadBlockAsync(char[] buffer, int index, int count)

    Parameters

    • buffer

      When this method returns, contains the specified character array with the values between index and (index + count - 1) replaced by the characters read from the current source.

    • index

      The position in buffer at which to begin writing.

    • count

      The maximum number of characters to read. If the end of the string is reached before the specified number of characters is written into the buffer, the method returns.

    Returns

    • A task that represents the asynchronous read operation. The value of the TResult parameter contains the total number of bytes read into the buffer. The result value can be less than the number of bytes requested if the number of bytes currently available is less than the requested number, or it can be 0 (zero) if the end of the string has been reached.

    Exceptions

    Overrides

  • ReadLine()

    Reads a line of characters from the current string and returns the data as a string.

    public override string ReadLine()

    Returns

    • The next line from the current string, or null if the end of the string is reached.

    Exceptions

    Overrides

  • ReadLineAsync()

    Reads a line of characters asynchronously from the current string and returns the data as a string.

    [ComVisible(false)]
    public override Task<string> ReadLineAsync()

    Returns

    • A task that represents the asynchronous read operation. The value of the TResult parameter contains the next line from the string reader, or is null if all the characters have been read.

    Exceptions

    Overrides

  • ReadToEnd()

    Reads all characters from the current position to the end of the string and returns them as a single string.

    public override string ReadToEnd()

    Returns

    • The content from the current position to the end of the underlying string.

    Exceptions

    Overrides

  • ReadToEndAsync()

    Reads all characters from the current position to the end of the string asynchronously and returns them as a single string.

    [ComVisible(false)]
    public override Task<string> ReadToEndAsync()

    Returns

    • A task that represents the asynchronous read operation. The value of the TResult parameter contains a string with the characters from the current position to the end of the string.

    Exceptions

    Overrides

Details

Namespace

System.IO

Assembly

System.IO.dll

See Also