(setq str1 '("123abc-de23f" "1abc-f123" "23abc" "23abcd23" "abc31de23"))
(setq str2 '("123abc-de23f" "1abc-f123" "32acd" "23abcd23" "abc31de23"))
(fun str1) ---> ("abc" "23")
(fun str2) ---> nil
why not (fun str2) ---> ("a" "c" "2" "3") ?Code: [Select](fun str2) ---> nil
(defun foo ( strlist / moo tmp ptn result )
(defun moo ( s / i r )
(while (< 0 (strlen s))
(repeat (setq i (strlen s))
(setq r (cons (substr s 1 i) r) i (1- i))
)
(setq s (substr s 2))
)
(reverse r)
)
(foreach a (setq tmp (mapcar 'moo strlist))
(foreach i a
(and
(vl-every
(function (lambda (b) (member i b)))
(vl-remove a tmp)
)
(null (member i result))
(setq result (cons i result))
)
)
)
(foreach i (vl-sort result (function (lambda (a b) (< (strlen a) (strlen b)))))
(and
(setq ptn (strcat "?" i "," i "?"))
(vl-some
(function (lambda (s) (wcmatch s ptn)))
(setq tmp (vl-remove i result))
)
(setq result tmp)
)
)
(vl-sort result '<)
)
In your mind should it return something else?there's nothing on my mind :)
(defun foo ( strlist / moo tmp ptn result )
(defun moo ( s / i r )
(while (< 1 (strlen s)) ;; was (< 0 (strlen s))
(repeat (setq i (strlen s))
(if (< 1 i) (setq r (cons (substr s 1 i) r) i (1- i)))
;; was (setq r (cons (substr s 1 i) r) i (1- i))
)
(setq s (substr s 2))
)
(reverse r)
)
(foreach a (setq tmp (mapcar 'moo strlist))
(foreach i a
(and
(vl-every
(function (lambda (b) (member i b)))
(vl-remove a tmp)
)
(null (member i result))
(setq result (cons i result))
)
)
)
(foreach i (vl-sort result (function (lambda (a b) (< (strlen a) (strlen b)))))
(and
(setq ptn (strcat "?" i "," i "?"))
(vl-some
(function (lambda (s) (wcmatch s ptn)))
(setq tmp (vl-remove i result))
)
(setq result tmp)
)
)
(vl-sort result '<)
)
(foreach lst
'(
("123abc-de23f" "1abc-f123" "23abc" "23abcd23" "abc31de23")
("123abc-de23f" "1abc-f123" "32acd" "23abcd23" "abc31de23")
("cbc" "abc")
("babac" "ababc")
)
(princ
(strcat "\n"
(vl-prin1-to-string lst)
" >> "
(vl-prin1-to-string (foo lst))
)
)
(princ)
)
Glad to hear you're learning.
This variant eschews individual chars (changes commented).