Function String Manipulations Class

CharacterEveryNthCharacter

Extracts characters from a string by stepping through it vStep positions at a time. Stops when the beginning or end of the source string vString is reached. Inverse of the MergeStrings function.

Signature (Visual Basic / VBA)

Public Function CharacterEveryNthCharacter( _
      ByVal vString As Variant _
    , Optional ByVal vStart As Variant _
    , Optional ByVal vStep As Variant _
    ) As Variant

Code Example

    CharacterEveryNthCharacter("ABCDEFGHIJ", 2, 3) = "BEH"

Parameters

Parameter Description
vString The string whose characters are to be samples. Function returns Null when vString is Null or cannot be fixed up to a String.
vStart The starting character position within string vString. When missing or Null or non-numeric, vStart defaults to 1 (one) if vStep is positive, or vStart defaults to the length of vString if vStep is negative.
vStep The number of character positions to move between each sample. Use a positive step to move from left-to-right and a negative step to move from right-to-left. vStep defaults to 1 (one) when it is missing or Null or cannot be fixed up to a number. Function returns an empty string when vStep is 0 (zero).