<-- Previous || Up || Next -->

Run Length Encode Function
Co Decs Class

Public Function RunLengthEncode( _
      ByVal vValue As Variant _
    , Optional ByVal vRLEChar As Variant _
    ) As Variant

Encode a string by replacing repeated runs of the same character with a run length code strings.
The run length code strings describe the character which is repeated and the number of times it was repeated.

Examples:
    RunLengthEncode("ABBCCCDDDDEEEEE") = "ABBCCC" + Chr$(255) + Chr$(4) + "D" + Chr$(255) + Chr$(5) + "E"
    RunLengthEncode("This is a test.") = "This is a test."
See also:
    RunLengthDecode Function
    RunLengthEncodePrintable Function
    CompressString Function
vValue: The string that is to be run-length encoded. Function returns Null if vValue is Null or cannot be fixed up to a String.

vRLEChar: The character which is to introduce the run-length codes within the encoded string. Note: Special argument fix-up code. If vRLEChar is a string, the ASCII value of the first character in the string is used as the run-length character. vRLEChar defaults to the character with ASCII value 255 if vRLEChar is an empty string.

If vRLEChar is numeric, then the character with that ASCII value is used as the run-length character.

vRLEChar defaults to the character with ASCII value 255 if vRLEChar is missing or Null or cannot be fixed up to either a string or number.

Note: Occurrences of the run-length character within the string vValue are replaced with a run-length code string because the run-length character always introduces such codes. In such cases, within the run-length code string, the character being repeated is the run-length character itself and the repeat count is one.

Note: Run-length code strings are comprised of the run-length character, the character whose ASCII value is the repeat count, and the character being repeated.

Copyright 1996-1999 Entisoft
Entisoft Tools is a trademark of Entisoft.