Jump to content

Leaderboard

Popular Content

Showing content with the highest reputation on 11/10/2020 in all areas

  1. How about: (defun foo ( l / a b ) (setq a (bar l) b (bar (mapcar '(lambda ( x ) (vl-list->string (reverse (vl-string->list x)))) l)) ) (list (substr (car l) 1 a) (mapcar '(lambda ( x ) (substr x (1+ a) (- (strlen x) a b))) l) (substr (car l) (- (strlen (car l)) b -1)) ) ) (defun bar ( l ) (apply 'min (mapcar '(lambda ( s ) (vl-string-mismatch (car l) s)) (cdr l))) ) _$ (foo '("Level 1 Floor Plan" "Level 2 Floor Plan" "Level 2b Floor Plan" "Level 3 Floor Plan")) ("Level " ("1" "2" "2b" "3") " Floor Plan") If you want case-insensitivity, simply include the ignore-case argument for the vl-string-mismatch function.
    1 point
  2. (defun foo ( strlst / findpre itm pre suf ) (defun findpre ( strlst k / str ) (if (null itm) (setq itm (car strlst)) ) (setq str (substr itm 1 k)) (if (vl-every '(lambda ( x ) (wcmatch x (strcat str "*"))) strlst) (findpre strlst (1+ k)) (substr str 1 (1- (strlen str))) ) ) (setq pre (findpre strlst 1)) (setq itm nil) (setq strlst (mapcar 'vl-list->string (mapcar 'reverse (mapcar 'vl-string->list strlst)))) (setq suf (vl-list->string (reverse (vl-string->list (findpre strlst 1))))) (setq strlst (mapcar 'vl-list->string (mapcar 'reverse (mapcar 'vl-string->list strlst)))) (setq strlst (mapcar '(lambda ( x ) (vl-string-trim pre (vl-string-trim suf x))) strlst)) (list pre strlst suf) ) ;;; (foo '("Level 1 Floor Plan" "Level 2 Floor Plan" "Level 2b Floor Plan" "Level 3 Floor Plan")) ;;; ("Level " ("1" "2" "2b" "3") " Floor Plan") HTH. M.R.
    1 point
  3. Yes, but can't post until later. May need tweaking.
    1 point
×
×
  • Create New...