BinaryReader: ReadChars |
Reads the specified number of characters from the current stream, returns the data in a character array, and advances the current position in accordance with the Encoding used and the specific character being read from the stream.
Public Function ReadChars( ByVal Count As Long ) As Integer ( )
BinaryReader does not restore the file position after an unsuccessful read operation.
The following example writes five characters to a stream then reads them all back at once using ReadChars.
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) Dim Chars() As Integer Dim Char As Variant Chars = Reader.ReadChars(5) Debug.Print CorString.Format("Read {0} characters.", CorArray.Length(Chars)) For Each Char In Chars PrintChar Char Next 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. ' ' Read 5 characters. ' 72 = "H" ' 101 = "e" ' 108 = "l" ' 108 = "l" ' 111 = "o"