;;;-------------------strtok.lsp------------ ;;;creates a list of tokens from a delimited string ;;;delim must be one distinct character, but may be repeated ;;;----------------------------------------- (defun strtok (str delim / out pos) (setq delim (ascii delim)) (while (setq pos (vl-string-position delim str)) (if (> pos 0);not just adjacent delimiters (setq out (cons (substr str 1 pos) out)) ) (setq str (substr str (+ 2 pos))) ) (if (> (strlen str) 0);not a trailing delimiter (reverse (cons str out)) (reverse out) ) ) ;;;-------------------strtokm.lsp------------ ;;;creates a list of tokens from a delimited string ;;;delim is a string which defines all possible delimiting chars ;;;any or all of which may be intermixed and/or repeated ;;;----------------------------------------- (defun strtokm (str delim / 1st out pos sub) ;;first change all possible delimiters to just one ascii value (setq sub "" 1st (substr delim 1 1) ) (repeat (strlen delim) (setq sub (strcat 1st sub)) ) (setq str (vl-string-translate delim sub str)) ;;now proceed as in strtok (setq delim (ascii delim)) (while (setq pos (vl-string-position delim str)) (if (> pos 0);not just adjacent delimiters (setq out (cons (substr str 1 pos) out)) ) (setq str (substr str (+ 2 pos))) ) (if (> (strlen str) 0);not a trailing delimiter (reverse (cons str out)) (reverse out) ) )