public class StringReader : TextReader
Object
MarshalByRefObject
TextReader
StringReaderThis type implements IDisposable.
mscorlib
BCL
Implements a TextReader that reads from a string.
System.IO Namespace
StringReader Constructors
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
public StringReader(string s);
Constructs and initializes a new instance of the StringReader class that reads from the specified string.
- s
- The String to be initialized to.
Exception Type Condition ArgumentNullException s is null
.
System.IO.StringReader Class, System.IO Namespace
public override void Close();
Closes the StringReader .
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.
]
System.IO.StringReader Class, System.IO Namespace
protected override void Dispose(bool disposing);
Releases system resources used by the current instance.
- disposing
true
to release both managed and unmanaged resources;false
to release only unmanaged resources.
When the disposing parameter istrue
, this method releases all resources held by any managed objects that this StringReader references. This method invokes theDispose()
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) .]
System.IO.StringReader Class, System.IO Namespace
public override int Peek();
Returns the next available character but does not advance the reader's position in the underlying string.
The next character to be read as a Int32 , or -1 if no more characters are available.
Exception Type Condition ObjectDisposedException The current reader is closed.
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.
]
System.IO.StringReader Class, System.IO Namespace
public override int Read(char[] buffer, int index, int count);
Reads a block of characters from the input string.
- 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.
A Int32 containing the total number of characters read into the buffer, or zero if the end of the underlying string has been reached.
Exception Type Condition ArgumentNullException buffer is null
.ArgumentException (index + count ) > buffer .
Length.ArgumentOutOfRangeException index < 0 - or-
count < 0.
ObjectDisposedException The current reader is closed.
[Note: This method overrides System.IO.TextReader.Read.]
System.IO.StringReader Class, System.IO Namespace
public override int Read();
Reads the next character from the input string and advances the character position by one character.
The next character from the underlying string as a Int32 , or -1 if no more characters are available.
Exception Type Condition ObjectDisposedException The current reader is closed.
[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.
]
System.IO.StringReader Class, System.IO Namespace
public override string ReadLine();
Reads a line from the underlying string.
A String containing the next line from the underlying string, ornull
if the end of the underlying string is reached.
Exception Type Condition ObjectDisposedException The current reader is closed. OutOfMemoryException There is insufficient memory to allocate a buffer for the returned string.
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.]
System.IO.StringReader Class, System.IO Namespace
public override string ReadToEnd();
Returns the underlying string from the current position to the end.
A String containing the content from the current position to the end of the underlying string.
Exception Type Condition ObjectDisposedException The current reader is closed. OutOfMemoryException There is insufficient memory to allocate a buffer for the returned string.
[Note: This method overrides System.IO.TextReader.ReadToEnd.]
System.IO.StringReader Class, System.IO Namespace