Author Topic: Use of %1 in autolisp routine  (Read 5915 times)

0 Members and 1 Guest are viewing this topic.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Use of %1 in autolisp routine
« Reply #15 on: August 31, 2009, 07:13:26 PM »
Just revisited this function & made some modifications.
Code: [Select]
;;  CAB 08.31.09
(defun str-format (str lst / r)
  (mapcar '(lambda (x y)
    (while (vl-string-search y str 0)
      (setq str (vl-string-subst (vl-princ-to-string x) y str)))
  )
lst
         (mapcar '(lambda(x)
           (strcat "%" (itoa(if r (setq r (1+ r))(setq r 1))))) lst)
  )
  str
)

 
Code: [Select]
(str-format "As you wish number %1, %2 is my favorite %3." (list 1 pi "number"))"As you wish number 1, 3.14159 is my favorite number."
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

Lee Mac

  • Seagull
  • Posts: 12928
  • London, England
Re: Use of %1 in autolisp routine
« Reply #16 on: September 01, 2009, 07:07:53 AM »
Very nice Alan, definitely keeping that one   ;-)

ElpanovEvgeniy

  • Water Moccasin
  • Posts: 1569
  • Moscow (Russia)
Re: Use of %1 in autolisp routine
« Reply #17 on: September 01, 2009, 09:15:03 AM »
Code: [Select]
(defun str-format-recursion (s l)
 (if (wcmatch s "*%#*")
  (if (wcmatch s "%#*")
   (strcat (vl-princ-to-string (nth (1- (atoi (substr s 2))) l))
           (str-format (substr s 3) l)
   ) ;_  strcat
   (strcat (substr s 1 1) (str-format (substr s 2) l))
  ) ;_  if
  s
 ) ;_  if
)

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Use of %1 in autolisp routine
« Reply #18 on: September 01, 2009, 09:16:10 AM »
Thanks Lee.
As you probably know it was inspired by the Express Tools subroutine.
Code: [Select]
(princ (acet-str-format "\nCurrent settings: Mode = %1, Radius = %2" sTrim sRad))
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.