BinaryReader: ReadChar

ReadChar

Reads the next decode character in the stream, and advances the position the number of bytes requirece to assemble a single character.



 Public Function ReadChar ( ) As Long

Return Values

Long -  The next character in the stream.

Remarks

If no characters are left in the stream, and EndOfStreamException is thrown.

Exceptions

Exception Condition
EndOfStreamExceptionThe end of the stream is reached.
ObjectDisposedExceptionThe stream is closed.
IOExceptionAn I/O error occurs.
ArgumentExceptionA surrogate character was read.

Examples

The following example writes five characters to a stream then reads them back one character at a time using ReadChar.

Public Sub Main()
    Dim Source As New MemoryStream
    Dim Reader As BinaryReader
    Dim Writer As BinaryWriter
    
    Set Writer = NewBinaryWriter(Source)
    Writer.WriteValue NewChars("H", "e", "l", "l", "o")    
    
    Source.Position = 0
    
    Set Reader = NewBinaryReader(Source)
    
    PrintChar Reader.ReadChar
    PrintChar Reader.ReadChar
    PrintChar Reader.ReadChar
    PrintChar Reader.ReadChar
    PrintChar Reader.ReadChar
End Sub

Private Sub PrintChar(ByVal Char As Integer)
    Debug.Print CorString.Format("{0,3} = ""{0:$}""", Char)
End Sub

' This example code produces the following output.
'
'     72 = "H"
'    101 = "e"
'    108 = "l"
'    108 = "l"
'    111 = "o"

See Also

Project CorLib Overview

Class BinaryReader Overview

Read

ReadChars

PeekChar

CorString

Constructors