Author Topic: String Counting  (Read 2914 times)

0 Members and 1 Guest are viewing this topic.

hudster

  • Gator
  • Posts: 2848
String Counting
« on: October 22, 2005, 04:15:01 AM »
How can I count the number of characters in a string, entered using "getstring",  and then delete the same number of characters from the end of another string.
Revit BDS 2017, 2016, 2015, 2014, AutoCAD 2017, 2016, Navisworks 2017, 2016, BIM360 Glue

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: String Counting
« Reply #1 on: October 22, 2005, 06:03:47 AM »
Code: [Select]
(defun c:test ()
  (setq originalString "Something like this perhaps would work.")
  (setq StringLength (strlen (setq tmp (getstring "Enter a string : "))))
  (setq newString (substr originalString
                          1
                          (- (strlen originalString) StringLength)
                  )
  )
)
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: String Counting
« Reply #2 on: October 22, 2005, 06:08:54 AM »
If you cant work out what's happening in that routine, just yell ...
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

Fatty

  • Guest
Re: String Counting
« Reply #3 on: October 22, 2005, 06:23:07 AM »
How can I count the number of characters in a string, entered using "getstring",  and then delete the same number of characters from the end of another string.

Hi Hudster

This one is very quick and dirty but it seems like work for me
Please spell my stupid prompts

Thank you

F.

Code: [Select]
(defun cut-tail (/ elist en ent new_str patt strng typ)
  (setq patt (getstring T "\nType pattern to cut :\n"))
  (setq ent (entsel "\nSelect text to cut the tail : "))
  (while (not (wcmatch (setq typ (cdr (assoc 0 (entget (car ent)))))
       "TEXT,MTEXT"))
    (princ "\nPlease select text or mtext!")
    (setq ent (entsel "\nSelect text to cut the tail : "))
    )
  (setq en    (car ent)
elist (entget en))
  (setq strng (cdr (assoc 1 elist)))
  (if (eq typ "MTEXT")
    (progn
      (setq new_str (substr (cdr (assoc 1 (entget (car ent))))
    1
    (- (strlen strng) (strlen patt) (strlen "\\P"))))
      (setq elist (subst (cons 1 new_str) (assoc 1 elist) elist))
      (entmod elist)
      (entupd en))
    (progn
      (setq new_str (substr (cdr (assoc 1 (entget (car ent))))
    1
    (- (strlen strng) (strlen patt))))
      (setq elist (subst (cons 1 new_str) (assoc 1 elist) elist))
      (entmod elist)
      (entupd en)
      )
    )
  (princ)
  )
;CaLL: (cut-tail)