Other previous solutions make the division of the string only to the space character, in this solution we can select any other character:
(defun splitchr (str ch)
(setq kk 1
lst1 (list)
)
(while (<= kk (strlen str))
(setq chr "")
(while (and (/= (substr str kk 1) ch)(<= kk (strlen str)))
(setq chr (strcat chr (substr str kk 1)))
(setq kk (+ 1 kk))
)
(setq lst1 (append lst1 (list chr) ))
(setq kk (+ 1 kk))
)
)
;;; exemple: (splitchr "cdscsd,vfdvdfv dfv, dssdcv" ",")
;;; return lst1-> ("cdscsd" "vfdvdfv dfv" "dssdcv")
Robert McNeel & Associates free product DOSLIB does this nicely.
Here's what I use...
;;--------------------------------------------------------- ;; Function to convert a string with delimiters into a list ;; pat is the delimiter and can contain multiple characters (defun @str2list (str pat / i j n lst) (cond ((/= (type str)(type pat) 'STR)) ((= str pat)'("")) (T (setq i 0 n (strlen pat)) (while (setq j (vl-string-search pat str i)) (setq lst (cons (substr str (1+ i)(- j i)) lst) i (+ j n) ) ) (reverse (cons (substr str (1+ i)) lst)) ) ) )
John F. Uhden
P.S I contacted McNeal & Associates some years ago about licensing DOSLIB for use within commercial products.
They informed me that DOSLIB may be included in any user's commercial products without royalty or fee. DOSLIB contains a treasure of library routines that will greatly simplify your programming effort so you can move on to the specific coding that only you can provide for your routines.