Function String Manipulations Class

MergeStrings

Creates a string by interspersing the characters from the two input strings. Inverse of the SplitStrings and CharacterEveryNthCharacter functions.

Signature (Visual Basic / VBA)

Public Function MergeStrings( _
      ByVal vOddPosChars As Variant _
    , ByVal vEvenPosChars As Variant _
    ) As Variant

Code Examples

    MergeStrings("12345", "ABCDE") = "1A2B3C4D5E"
    MergeStrings("12345", "ABCDEFGHIJ") = "1A2B3C4D5E" ' #2
    "1A2B3C4D5EFGHIJ" or "1A2B3C4D5E F G H I J"

Parameters

Parameter Description
vOddPosChars The string containing the characters which will fill the odd-numbered character positions in the result. Function returns Null if vOddPosChars is Null or cannot be fixed up to a String.
vEvenPosChars The string containing the characters which will fill the even-numbered character positions in the result. Function returns Null if vEvenPosChars is Null or cannot be fixed up to a String.

Notes & Version History

Note If the two strings have different lengths, the characters in the longer string past the length of the shorter strings are ignored, as in example #2 where "FGHIJ" is ignored--the function does not return something like