jon123 Posted May 10, 2021 Posted May 10, 2021 Hi , I found that lisp below in a previous thread. It works great at removing characters from the right side of the string. Can someone please point out to me how to change it to remove characters from the left side of the string, eg the first 3 characters. (defun c:Char-Rem-R ( / ent idx nol ss tmp) (command "UNDO" "BE") (if (setq ss (ssget "_:L" '((0 . "MTEXT,TEXT")))) (progn (setq nol (getint "\n Number of Characters to Remove from End of String <1>:")) (if (eq nol nil) (setq nol 1)) (repeat (setq idx (sslength ss)) (setq ent (entget(ssname ss (setq idx (1- idx))))) (if (> (strlen (cdr(assoc 1 ent))) nol) (progn (setq ent (subst (cons 1 (substr (cdr(assoc 1 ent)) 1 (-(strlen (cdr(assoc 1 ent))) nol ))) (assoc 1 ent) ent) ) (entmod ent) ) (setq tmp 1) ) ) ) (princ "No Text Selected. Please Try Again") ) (command "UNDO" "END") (if (= tmp 1) (princ "\nSome Selected Text Have Less Characters than Number of Characters to Remove! (No Characters removed from these)") ) (princ) ) original thread: Many thanks for the help. Quote
Tharwat Posted May 10, 2021 Posted May 10, 2021 Hi, Please note is that the formatted Mtext needs another way of coding and more codes so the following should work flawlessly on all other scenarios and besides that it will trim strings if the omitted string from the first trim starts with empty space(s). (defun c:Test (/ int sel get str) ;; Tharwat - Date: 10.May.2021 ;; (and (or *txt:trm* (setq *txt:trm* 1)) (setq *txt:trm* (cond ((getint (strcat "\nSpecify number of chars to trim < " (itoa *txt:trm*) " > : " ) ) ) (*txt:trm*) ) ) (princ "\nSelect Texts to trim : ") (setq sel (ssget "_:L" '((0 . "*TEXT")))) (repeat (setq int (sslength sel)) (setq int (1- int) get (entget (ssname sel int)) str (assoc 1 get) ) (and (< *txt:trm* (strlen (cdr str))) (setq get (entmod (subst (cons 1 (substr (cdr str) (1+ *txt:trm*))) str get ) ) ) (while (wcmatch (cdr (setq str (assoc 1 get))) " *") (setq get (entmod (subst (cons 1 (substr (cdr str) 2)) str get))) ) ) ) ) (princ) ) Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.