May 2, 2002 #1 xxeRexx Programmer Dec 1, 2008 5 US TO LISP EXPERTS OUT THERE: I'M A NEWBIE AT AUTOLISP, TRYING TO DO A PROGRAM, CAN ANYBODY HELP ME WITH THIS? HOW CAN I CONVERT A STRING LIKE: "123 456 789" TO A LIST CONTAINING REAL NUMBERS? THANX FOR ANY HELP!!!
TO LISP EXPERTS OUT THERE: I'M A NEWBIE AT AUTOLISP, TRYING TO DO A PROGRAM, CAN ANYBODY HELP ME WITH THIS? HOW CAN I CONVERT A STRING LIKE: "123 456 789" TO A LIST CONTAINING REAL NUMBERS? THANX FOR ANY HELP!!!
May 6, 2002 #2 borgunit Programmer Mar 25, 2002 373 US Hi, Here is a snippet that should get you there. BU ;;STRPARSE FOR PARSING STRING (and keeping null tokens) (defun STRPARSE (STRNG CHS / LEN C L S CHSL CNT) ;;delim==one-of-chs. (setq CHSL (STRTOL CHS)) (setq LEN (strlen STRNG) S "" CNT (1+ LEN) ) (while (> (setq CNT (1- CNT)) 0) (setq C (substr STRNG CNT 1)) (if (member C CHSL) (if (/= CNT LEN) ;; "1,2," -> ("1" "2" and not ("1" "2" "" (setq L (cons S L) S "" ) ) (setq S (strcat C S)) ) ) (cons S L) ;; ",1,2" -> ("" "1" "2" ) ;------------------------------------------------------------------------------ (defun STRTOL (S / LST C) (repeat (setq C (strlen S)) (setq LST (cons (substr S C 1) LST) C (1- C) ) ) LST ) ;------------------------------------------------------------------------------ ;(setq I_QTY (length (STRPARSE "123 456 789" " ")) ;i.e. of use- this returns ("123" "456" "789" (defun RUNTEST () (setq NEWLIST (list)) (foreach ITEM (STRPARSE "123 456 789" " " ;(setq REALITEM (atof ITEM)) (setq NEWLIST (cons (atof ITEM) NEWLIST)) ) (reverse NEWLIST) ) Upvote 0 Downvote
Hi, Here is a snippet that should get you there. BU ;;STRPARSE FOR PARSING STRING (and keeping null tokens) (defun STRPARSE (STRNG CHS / LEN C L S CHSL CNT) ;;delim==one-of-chs. (setq CHSL (STRTOL CHS)) (setq LEN (strlen STRNG) S "" CNT (1+ LEN) ) (while (> (setq CNT (1- CNT)) 0) (setq C (substr STRNG CNT 1)) (if (member C CHSL) (if (/= CNT LEN) ;; "1,2," -> ("1" "2" and not ("1" "2" "" (setq L (cons S L) S "" ) ) (setq S (strcat C S)) ) ) (cons S L) ;; ",1,2" -> ("" "1" "2" ) ;------------------------------------------------------------------------------ (defun STRTOL (S / LST C) (repeat (setq C (strlen S)) (setq LST (cons (substr S C 1) LST) C (1- C) ) ) LST ) ;------------------------------------------------------------------------------ ;(setq I_QTY (length (STRPARSE "123 456 789" " ")) ;i.e. of use- this returns ("123" "456" "789" (defun RUNTEST () (setq NEWLIST (list)) (foreach ITEM (STRPARSE "123 456 789" " " ;(setq REALITEM (atof ITEM)) (setq NEWLIST (cons (atof ITEM) NEWLIST)) ) (reverse NEWLIST) )