Upraviť

Zdieľať cez


StringReader.Read Method

Definition

Reads the next character or next set of characters from the input string.

Overloads

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 count.

Read()

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

Read(Span<Char>)

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

buffer
Span<Char>

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

Read(Char[], Int32, Int32)

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