Search code examples
lotus-dominolotusscript

Lotus NotesStream how to read character by character


How do read from a NotesStream character by character. i.e one character at a time in a loop. NoteasStream.Read(1) reads one character but returns a variant array which I am not able to convert to the specific character.


Solution

  • This way you can read byte by byte from stream

    Dim stream As NotesStream
    Dim bytes As variant
    ...
    Do
        bytes = stream.Read(1)
        Print bytes(0)
    Loop Until stream.IsEOS
    

    Probably more efficient is it to read more then just one byte at a time from stream

    Dim stream As NotesStream
    Dim bytes As variant
    ...
    Do
        bytes = stream.Read(32767)
        ForAll b In bytes
            Print b
        End ForAll
    Loop Until stream.IsEOS
    

    If you want to get characters instead of bytes one by one then you can use this

    Dim stream As NotesStream
    ...
    Dim buffer As String
    Dim i As Long
    Dim char As String
    buffer = stream.ReadText()
    For i=1 To Len(buffer)
        char = Mid(buffer, i, 1)
        Print char
    Next