On Sun, 27 Oct 1996 04:13:05 -0800, - Lu <email@example.com> wrote in comp.cad.autocad:
>> there are 14 paths and 12 pigs.
>> How can there be 24 ducks?
>> (Imaginary, of course.) Is there a lisp command that will
>> allow me to pick these lines of text, and recognize the
>> number(s) in each line, in order to, say, raise each number
>> by two? Leaving the sentence structure, etc, intact?
>This is one way. (I am sure there many other ways)
It may be
(defun mult2 ( strng) (strlgather (mapcar '(lambda(s / n) (if(zerop(setq n(atof s)))s (rtos (* n 2)))) (strlparse strng " ")) ;; parse by spaces " "))The LUPREC and DIMZIN will affect the result.
;;gather strings from list together again (defun strlgather(strl delims) (substr (apply'strcat(mapcar'(lambda(s)(strcat delims s))strl)) (1+ (strlen delims))))STRLPARSE is on my code directory at Reini Urban's great site (thanks Reini :-)) http://xarch.tu-graz.ac.at/autocad/lisp/
Here what I've got with it:
(mult2 "there's 12 ducks in 6 dishes")
"there's 24.0000 ducks in 12.0000 dishes"
Now if you want that to be done for each TEXT selected, you may use
(defun c:mult2(/ sel e d a1) (foreach e ;; allow implied selection (if (setq sel (ssget "I" '((0 . "TEXT")))) (seltol sel) (seltol (ssget '((0 . "TEXT"))))) (if (setq d (entget e) a1 (assoc 1 d)) (entmod (subst (cons 1 (mult2 (cdr a1))) a1 d)))))Selection-to-list SELTOL function is at the same http.
Have fun, -- Vladimir Nesterovsky ADS/LISP/C/C++ etc <firstname.lastname@example.org>