System.IO.StringReader Class

public class StringReader : TextReader

Base Types

Object
  MarshalByRefObject
    TextReader
      StringReader

This type implements IDisposable.

Assembly

mscorlib

Library

BCL

Summary

Implements a TextReader that reads from a string.

See Also

System.IO Namespace

Members

StringReader Constructors

StringReader Constructor

StringReader Methods

StringReader.Close Method
StringReader.Dispose Method
StringReader.Peek Method
StringReader.Read(char[], int, int) Method
StringReader.Read() Method
StringReader.ReadLine Method
StringReader.ReadToEnd Method


StringReader Constructor

public StringReader(string s);

Summary

Constructs and initializes a new instance of the StringReader class that reads from the specified string.

Parameters

s
The String to be initialized to.

Exceptions

Exception TypeCondition
ArgumentNullExceptions is null .

See Also

System.IO.StringReader Class, System.IO Namespace

StringReader.Close Method

public override void Close();

Summary

Closes the StringReader .

Description

Following a call to System.IO.StringReader.Close , other StringReader methods on the current instance will throw an exception.

[Note: This version of System.IO.StringReader.Close is equivalent to System.IO.StringReader.Dispose(System.Boolean)(true ).

This method overrides System.IO.Stream.Close.

]

See Also

System.IO.StringReader Class, System.IO Namespace

StringReader.Dispose Method

protected override void Dispose(bool disposing);

Summary

Releases system resources used by the current instance.

Parameters

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

Description

When the disposing parameter is true , this method releases all resources held by any managed objects that this StringReader references. This method invokes the Dispose() method of each referenced object.

[Note: System.IO.StringReader.Dispose(System.Boolean) can be called multiple times by other objects. When overriding System.IO.StringReader.Dispose(System.Boolean)(Boolean), be careful not to reference objects that have been previously disposed in an earlier call to System.IO.StringReader.Dispose(System.Boolean) .]

See Also

System.IO.StringReader Class, System.IO Namespace

StringReader.Peek Method

public override int Peek();

Summary

Returns the next available character but does not advance the reader's position in the underlying string.

Return Value

The next character to be read as a Int32 , or -1 if no more characters are available.

Exceptions

Exception TypeCondition
ObjectDisposedExceptionThe current reader is closed.

Description

The current position of the StringReader is not changed by this operation.

[Note: This method returns -1 is when the end of the underlying string is reached because a Unicode character can contain only values between hexadecimal 0x0000 to 0xFFFF (0 to 65535).

This method overrides System.IO.TextReader.Peek.

]

See Also

System.IO.StringReader Class, System.IO Namespace

StringReader.Read(char[], int, int) Method

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

Summary

Reads a block of characters from the input string.

Parameters

buffer
A Char array. 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
A Int32 that specifies the starting index in the buffer.
count
A Int32 that specifies the number of characters to read.

Return Value

A Int32 containing the total number of characters read into the buffer, or zero if the end of the underlying string has been reached.

Exceptions

Exception TypeCondition
ArgumentNullExceptionbuffer is null .
ArgumentException(index + count ) > buffer. Length.
ArgumentOutOfRangeExceptionindex < 0

- or-

count < 0.

ObjectDisposedExceptionThe current reader is closed.

Description

[Note: This method overrides System.IO.TextReader.Read.]

See Also

System.IO.StringReader Class, System.IO Namespace

StringReader.Read() Method

public override int Read();

Summary

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

Return Value

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

Exceptions

Exception TypeCondition
ObjectDisposedExceptionThe current reader is closed.

Description

[Note: This method returns -1 is when the end of the underlying string is reached because a Unicode character can contain only values between hexadecimal 0x0000 to 0xFFFF (0 to 65535).

This method overrides System.IO.TextReader.Read.

]

See Also

System.IO.StringReader Class, System.IO Namespace

StringReader.ReadLine Method

public override string ReadLine();

Summary

Reads a line from the underlying string.

Return Value

A String containing the next line from the underlying string, or null if the end of the underlying string is reached.

Exceptions

Exception TypeCondition
ObjectDisposedExceptionThe current reader is closed.
OutOfMemoryExceptionThere is insufficient memory to allocate a buffer for the returned string.

Description

A line is defined as a sequence of characters followed by a carriage return (0x000d), a line feed (0x000a), or a carriage return immediately followed by a line feed. The resulting string does not contain the terminating character(s).

[Note: This method overrides System.IO.TextReader.ReadLine.]

See Also

System.IO.StringReader Class, System.IO Namespace

StringReader.ReadToEnd Method

public override string ReadToEnd();

Summary

Returns the underlying string from the current position to the end.

Return Value

A String containing the content from the current position to the end of the underlying string.

Exceptions

Exception TypeCondition
ObjectDisposedExceptionThe current reader is closed.
OutOfMemoryExceptionThere is insufficient memory to allocate a buffer for the returned string.

Description

[Note: This method overrides System.IO.TextReader.ReadToEnd.]

See Also

System.IO.StringReader Class, System.IO Namespace