Author Topic: how can i add to the end of a certain item in a list  (Read 1869 times)

0 Members and 1 Guest are viewing this topic.

andrew_nao

  • Guest
how can i add to the end of a certain item in a list
« on: July 20, 2009, 03:57:23 PM »
I have a lisp that writes a list of info to a text file.
in this list i have a specific item that has less then 12 characters
(its always 8)
i would like take this specific list item and add spaced to the end of it to make it 12 characters long (its a format thing)

I tried adding the spaced in the beginning of the list item
but doing that ended up not displaying the list item.
sorta like it pushed it off the screen in the text file

here is what i used to add spaced to the beginning but returned undesired results.

Code: [Select]
(if (<(strlen (nth 0 dwg)) 12)
(setq dwg (subst "    " (nth 0 dwg) dwg))
)

does anyone have any code snippets to share that show me how to add spaced to the end of a specific list item

thanks for any help

never mind i figured out what i was doing wrong
thanks for looking

mods can remove this post
« Last Edit: July 20, 2009, 04:01:06 PM by andrew_nao »

hermanm

  • Guest
Re: how can i add to the end of a certain item in a list
« Reply #1 on: July 20, 2009, 05:29:05 PM »
Code: [Select]
;;;----------------------pad-or-trunc------------------------
;;;  Purpose: Functions to pad or truncate a string
;;;           to a designated width
;;;  by Herman Mayfarth
;;;  str  : string to process
;;;  char : pad character
;;;  len  : required length of output string
;;;--------------------------------------------------------
;;pad right or truncate right
(defun padright-or-trunc (str char len )
  (if (> (strlen str) len )
    (substr str 1 len)
    (repeat (- len (strlen str))
      (setq str (strcat str char))
    )
  );if
)

;;pad left or truncate left
(defun padleft-or-trunc (str char len / sl)
  (if (> (setq sl (strlen str)) len )
    (substr str (- sl len) len)
    (repeat (- len (strlen str))
      (setq str (strcat char str))
    )
  );if
)

DEVITG

  • Bull Frog
  • Posts: 479
Re: how can i add to the end of a certain item in a list
« Reply #2 on: July 21, 2009, 07:44:31 AM »
Please try it

Code: [Select]
(setq dwg-list  (list"1234567890" "abcdefg" "34567"  "123456789012"    )   )

(defun add-to-n ( list$ char$ n /
dwg-list-1
DWG-LIST  ESP# ESP$ NEWDG
)
(foreach dwg list$
(setq esp$ "") 
(if (> (setq esp# (- n (strlen dwg)))0)
(Progn
  (repeat esp#
    (setq esp$ ( strcat esp$ char$))
    )
(setq newdg (strcat dwg esp$   ))
  (Setq dwg-list-1  (cons newdg dwg-list-1 ))

 );_ progn
(Setq dwg-list-1  (cons dwg dwg-list-1 ))
 
  );_ if
  );_ foreach
(setq dgw-list-2 (reverse dwg-list-1))
  )

(add-to-n dwg-list "&" 12)

Replace "&" by " "
Location @ Córdoba Argentina Using ACAD 2019  at Window 10

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
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.