Hi
thanks for all your contribution~
Because I often need to deal with txt data, so the delim is not only one char, but maybe like " \t\n,;"
(" \t\n,;" means " " "\t" "n" "," ";" can all be delims)
so, for a delim represent more than one char, I write such code, I hope you can shorten it
;;;by qjchen@gmail.com
(defun q:str:delim(str delim / l1 l2)
(setq str (vl-string->list str) delim (vl-string->list delim))
(while str
(if (not (member (car str) delim))
(setq l1 (cons (car str) l1))
(if l1 (setq l2 (cons (vl-list->string (reverse l1)) l2) l1 nil))
)
(setq str (cdr str))
)
(if l1 (setq l2 (cons (vl-list->string (reverse l1)) l2)))
(reverse l2)
)
(q:str:delim "a,bb c\tdd\ne" " ,\t\n")
(q:str:delim "a,bb c\tdd\ne" " ,\t\n")=> ("a" "bb" "c" "dd" "e")
before I wrote this my own code, I always use the following std-lib function, it can be used in Autocad R14
(defun STD-STRING->LIST (s / lst)
(if (= (type s) 'STR)
(while (/= s "")
(setq lst (cons (ascii (substr s 1 1)) lst) s (substr s 2))
)
)
(reverse lst)
)
(defun STD-STRTOK (s delims / len s1 i c lst)
(setq delims (std-string->list delims)
len (strlen s) s1 "" i (1+ len)
)
(while (> (setq i (1- i)) 0)
(setq c (substr s i 1))
(if (member (ascii c) delims)
(if (/= s1 "") (setq lst (cons s1 lst) s1 ""))
(setq s1 (strcat c s1))
)
)
(if (/= s1 "") (cons s1 lst) lst)
)
(STD-STRTOK "a,bb c\tdd\ne" " ,\t\n")