StringReader.Read Method
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Reads the next character or next set of characters from the input string.
Read() |
Reads the next character from the input string and advances the character position by one character. |
Read(Span<Char>) |
Reads all the characters from the input string, starting at the current position, and advances the current position to the end of the input string. |
Read(Char[], Int32, Int32) |
Reads a block of characters from the input string and advances the character position by |
- Source:
- StringReader.cs
- Source:
- StringReader.cs
- Source:
- StringReader.cs
Reads the next character from the input string and advances the character position by one character.
public:
override int Read();
public override int Read ();
override this.Read : unit -> int
Public Overrides Function Read () As Integer
Returns
The next character from the underlying string, or -1 if no more characters are available.
Exceptions
The current reader is closed.
Examples
This code example is part of a larger example provided for the StringReader class.
convertedCharacter = Convert::ToChar( intCharacter );
if ( convertedCharacter == '.' )
{
strWriter->Write( ".\n\n" );
// Bypass the spaces between sentences.
strReader->Read();
strReader->Read();
}
convertedCharacter = (char)intCharacter;
if(convertedCharacter == '.')
{
strWriter.Write(".\n\n");
// Bypass the spaces between sentences.
strReader.Read();
strReader.Read();
}
convertedCharacter = Convert.ToChar(intCharacter)
If convertedCharacter = "."C Then
strWriter.Write("." & vbCrLf & vbCrLf)
' Bypass the spaces between sentences.
strReader.Read()
strReader.Read()
Remarks
This method overrides the TextReader.Read method.
The following table lists examples of other typical or related I/O tasks.
To do this... | See the example in this topic... |
---|---|
Create a text file. | How to: Write Text to a File |
Write to a text file. | How to: Write Text to a File |
Read from a text file. | How to: Read Text from a File |
Append text to a file. | How to: Open and Append to a Log File File.AppendText FileInfo.AppendText |
Get the size of a file. | FileInfo.Length |
Get the attributes of a file. | File.GetAttributes |
Set the attributes of a file. | File.SetAttributes |
Determine if a file exists. | File.Exists |
Read from a binary file. | How to: Read and Write to a Newly Created Data File |
Write to a binary file. | How to: Read and Write to a Newly Created Data File |
See also
Applies to
.NET 9 and other versions
Product | Versions |
---|---|
.NET | Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9 |
.NET Framework | 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1 |
.NET Standard | 1.0, 1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 2.0, 2.1 |
UWP | 10.0 |
- Source:
- StringReader.cs
- Source:
- StringReader.cs
- Source:
- StringReader.cs
Reads all the characters from the input string, starting at the current position, and advances the current position to the end of the input string.
public:
override int Read(Span<char> buffer);
public override int Read (Span<char> buffer);
override this.Read : Span<char> -> int
Public Overrides Function Read (buffer As Span(Of Char)) As Integer
Parameters
When this method returns, contains the characters read from the current source. If the total number of characters read is zero, the span remains unmodified.
Returns
The total number of characters read into the buffer.
Exceptions
The current string reader instance is closed.
Applies to
.NET 9 and other versions
Product | Versions |
---|---|
.NET | Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9 |
.NET Standard | 2.1 |
- Source:
- StringReader.cs
- Source:
- StringReader.cs
- Source:
- StringReader.cs
Reads a block of characters from the input string and advances the character position by count
.
public:
override int Read(cli::array <char> ^ buffer, int index, int count);
public override int Read (char[] buffer, int index, int count);
override this.Read : char[] * int * int -> int
Public Overrides Function Read (buffer As Char(), index As Integer, count As Integer) As Integer
Parameters
- buffer
- Char[]
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
- Int32
The starting index in the buffer.
- count
- Int32
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
buffer
is null
.
The buffer length minus index
is less than count
.
index
or count
is negative.
The current reader is closed.
Remarks
This method overrides TextReader.Read.
The method will read up to count
characters from the StringReader into the buffer
character array starting at position index
. Returns the actual number of characters read, or zero if the end of the string has been reached and no characters are read.
The following table lists examples of other typical or related I/O tasks.
To do this... | See the example in this topic... |
---|---|
Create a text file. | How to: Write Text to a File |
Write to a text file. | How to: Write Text to a File |
Read from a text file. | How to: Read Text from a File |
Append text to a file. | How to: Open and Append to a Log File File.AppendText FileInfo.AppendText |
Get the size of a file. | FileInfo.Length |
Get the attributes of a file. | File.GetAttributes |
Set the attributes of a file. | File.SetAttributes |
Determine if a file exists. | File.Exists |
Read from a binary file. | How to: Read and Write to a Newly Created Data File |
Write to a binary file. | How to: Read and Write to a Newly Created Data File |
See also
Applies to
.NET 9 and other versions
Product | Versions |
---|---|
.NET | Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9 |
.NET Framework | 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1 |
.NET Standard | 1.0, 1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 2.0, 2.1 |
UWP | 10.0 |
.NET feedback
.NET is an open source project. Select a link to provide feedback: