0 Members and 1 Guest are viewing this topic.
(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) ) ))
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.
(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)