Tested on Bricscad V17, recursion is very slow:
(progn
(setq Keys "$#*" String "$#*$#*ABC$#*DEF$#*$#*GHIJKL$#*MNOP$#*$#*")
(repeat 6 (setq String (strcat String Keys String)))
(print (strlen String)) (princ " strlen\n")
(princ)
)
2749 strlen
Elapsed milliseconds / relative speed for 16384 iteration(s):
(ALE STRING KEYS)......2938 / 11.89 <fastest>
(FOO KEYS STRING).....34922 / 1 <slowest>
...another bug with adjacent key, similar my first version:
(defun ALE (s d / p m l o r)
; 20170614 - version 1.03 for adjacent key (d)
(cond
( (setq
l (strlen d) p 0
m (vl-string-search d s 0)
)
(while m
(if (zerop (- m p))
(setq o (cons d o))
(setq o (cons d (cons (substr s (1+ p) (- m p)) o)))
)
(setq
p (+ m l)
m (vl-string-search d s p)
)
)
(if (= "" (setq r (substr s (1+ p))))
(reverse o)
(reverse (cons r o))
)
)
( (list s) )
)
)