BinaryReader: 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
If no characters are left in the stream, and EndOfStreamException is thrown.
Exception | Condition |
---|---|
EndOfStreamException | The end of the stream is reached. |
ObjectDisposedException | The stream is closed. |
IOException | An I/O error occurs. |
ArgumentException | A surrogate character was read. |
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"