Function String Manipulations Class

RepeatStringToLength

Like the built-in String$() function, except all of the characters in the string are repeated until string is of length vLength.

Signature (Visual Basic / VBA)

Public Function RepeatStringToLength( _
      ByVal vLength As Variant _
    , ByVal vRepeat As Variant _
    ) As Variant

Code Examples

       RepeatStringToLength(5, "ABC") = "ABCAB"
    whereas
       String$(5, "ABC") = "AAAAA"
       RepeatStringToLength(5, 65) = "AAAAA"
    assuming
       Chr$(65) = "A"
       Asc("A") = 65

Parameters

Parameter Description
vLength The (maximum) length of the result string. Function returns Null if vLength is Null or cannot be fixed up to a number.
vRepeat The string or character which is to be replicated until the result is of length vLength. Note: Special argument fix-up code. Function returns an empty string if vRepeat is an empty string. If vRepeat is a string, the entire string is repeated fully and/or partially until the resulting string has the specified length. If vRepeat is numeric, the string is constructed from the character with that ASCII value. Function returns Null when vRepeat is neither string nor numeric.