Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

AUTOLISP QUESTION...

Status
Not open for further replies.

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!!!
 
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)
)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top