Array ‘By Element’ functions

AINSERT

Reference

» Reference, Discussion, & Example Applications:

About

Inserts any string delimiter “d” between characters of an array “a” with a selectable pace “p” and selectable starting point “i”.

Inputs:

  • a : array
  • d : any string delimiter
  • p : integer, pace width
  • i : integer, index starting point, first delimiter will be placed in the ith position, or just after (i-1)th character, so for i ignored or i<=2, insert will start after 1st character

Code

M.S. Excel
AINSERT = LAMBDA(a, d, p, i,
    LET(
        ld, LEN(d),
        k, MAX(p, 1),
        j, MAX(k + 1, i),
        n, MAX(LEN(a)),
        IF(
            n < (j - 1),
            SUBSTITUTE(TRIM(SUBSTITUTE(a, d, " ")), " ", d),
            AINSERT(
                REPLACE(a, j, , d),
                d,
                k,
                j + 2 * (k + 1) - k - 1 + ld - 1
            )
        )
    )
);