@Kent1Cooper wrote:
Deleting spaces is easy, with certain (vl-string...) functions, but ... you clearly don't want to delete all spaces. Would the spaces you want to keep always be on either side of a number, and would there never be other numerical characters adjacent to spaces that you want to delete? ... something could probably be worked out.
Like this, for instance, also accounting for the period after MT in your example, followed by a space you want to keep. Limited testing, but it gives the desired result in the case of your example. If there are any other relationships involving spaces that should not be removed, they can be worked in if you define them unambiguously.
(defun RESXNP ; = Remove Extraneous Spaces eXcept around Number/after Period
(str / pos space 3char)
(setq str (vl-string-trim " " str)); remove any leading or trailing space(s)
(while (wcmatch str "* *"); still any multiple spaces?
(setq str (vl-string-subst " " " " str)); replace two spaces with one
); while
(setq pos 0)
(while (setq space (vl-string-position 32 str pos)); any space(s) remaining?
(setq 3char (substr str space 3)); space with adjacent characters both sides
(if (wcmatch 3char "# ?,? #,`. ?")
; either adjacent character is numerical, or preceding character is period
(setq pos (+ pos 2)); then: leave space, look next after following character
(setq ; else:
str (vl-string-subst (vl-string-subst "" " " 3char) 3char str); remove space
pos (1+ pos); look next after following character
); setq
); if
); while
str
); defun -- RESXNP
Usage:
Command: (resxnp "R O A D 18.00 MT. W I D E")
"ROAD 18.00 MT. WIDE"
The string can be entered explicitly as above, or can be fed in as a stored variable value, or (read-line) input from a text file, or whatever.
That just changes raw string content, independent of any drawing entity. It could be incorporated into a routine to "fix" Text/Mtext/Attribute content in a variety of ways -- you would need to decide whether you want to pick existing objects [and if so, whether collectively to be processed all at once, or one at a time to see each one updated as you pick it], or have it process all such objects in the drawing, or all of them on a particular Layer and/or in a particular Style, or process text content prior to using it to make new Text/Mtext objects, or ....
Kent Cooper, AIA