Function Co Decs Class

RunLengthEncodePrintable

Encode a string by replacing repeated runs of characters with a run length code. Accepts a string containing ASCII values between 0 and 255 and returns a run-length-encoded string whose characters all have ASCII values within the range from 32 to 126 inclusive.

Signature (Visual Basic / VBA)

Public Function RunLengthEncodePrintable( _
    ByVal vValue As Variant _
    ) As Variant

Code Examples

    RunLengthEncodePrintable("One" + vbCrLf + Chr$(9) + "Two") = "One}-}*})Two"
    RunLengthEncodePrintable("This is a test.") = "This is a test."
    0..31:    Chr$(125) + Chr$(N + 32)
    32..123:  Chr$(N)
    124..183: Chr$(125) + Chr$(N - 60)
    183..255: Chr$(126) + Chr$(N - 151)

Parameters

Parameter Description
vValue The string that is to be run-length encoded into a "printable" string. Function returns Null if vValue is Null or cannot be fixed up to a String.

Notes & Version History

Details This function is mainly used to represent strings containing "non-printable" characters using only "printable" characters, such as certain Visual Basic string expressions which must contain characters that Microsoft recommends should not appear in Visual Basic nor VBA Modules.
Algorithm Characters with the ASCII value on the left are replaced by the string on the right.