Subject: Re: Lisp help...How to separate numbers/letters?
Date: Sat, 02 Nov 1996 15:02:03 GMT
From: vnestr@netvision.net.il (Vladimir Nesterovsky)
Organization: IDAN Computers
Newsgroups: comp.cad.autocad,
Message-ID: <55fnf8$qdr@news.NetVision.net.il>
References: 1, 2,

On Sun, 27 Oct 1996 04:13:05 -0800, - Lu <learly@ix.netcom.com> wrote in comp.cad.autocad:

>rosie wrote:
>> 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:

Command: (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 <vnestr@netvision.net.il>