@Kent1Cooper wrote:
If your Mtext doesn't contain formatting codes involving numbers ..., nor any stacked fractions, but all numerical characters are always and only the ones you want removed, then something as simple as this ....
It also removes any leftover leading/trailing spaces, but not decimal points or hyphens or slashes of un-stacked fractions, foot or inch marks, etc. ....
And yet another way [with the same limitations as above], using a different approach involving the ASCII character codes that @joselggalan has brought up:
(vl-load-com)
(defun C:SNT (/ txtent txt) ; = Strip Numbers from Text
(prompt "\nTo Strip Numbers from Text,")
(if (setq ss (ssget '((0 . "*TEXT") (1 . "*#*"))))
(repeat (setq n (sslength ss))
(vla-put-TextString
(setq txtobj (vlax-ename->vla-object (ssname ss (setq n (1- n)))))
(vl-string-trim " "
(vl-list->string
(vl-remove-if '(lambda (x) (< 47 x 58)); dump if from 0 [48] to 9 [57]
(vl-string->list (vla-get-TextString txtobj)); as character codes
); ...remove...
); ...list...
); ...put...
); ...trim...
); repeat
); if
); defun
This should be faster than my previous routine, since this takes all of them out at once, whereas (vl-string-subst) replaces only the first instance of what it's aiming to replace, so it has to keep looking again, and since the earlier routine runs a substitution for every numerical character, even when not all are present.
Kent Cooper, AIA