deleting text spaces

deleting text spaces

sudarsann
Advocate Advocate
2,676 Views
5 Replies
Message 1 of 6

deleting text spaces

sudarsann
Advocate
Advocate

Ex: Text strings having "R     O  A    D  xx.xx MT. W    I       D  E". How to replace that text with "ROAD xx.xx MT. WIDE" by deleting the spaces using lisp. here xx.xx is the road wide (ex: 18.00, 30.00)

Lot of text strings in drawing files like above.

Is any lisp for the above problem.

 

Regards

Sudarsan

0 Likes
2,677 Views
5 Replies
Replies (5)
Message 2 of 6

vladimir_michl
Advisor
Advisor

I would use regular expressions to perform this type of replacement. The RegEx for this case will be:

 

search: (\D)\s+(?=\D)

replace: \1\2

 

Vladimir Michl, www.cadstudio.cz  www.cadforum.cz

 

 

0 Likes
Message 3 of 6

vladimir_michl
Advisor
Advisor

You can also use the updated srxText utility and its command SRXTEXT2 (free) to perform this regular expression replacement. See:

http://www.cadstudio.cz/en/apps/srxtext/

 

Vladimir Michl, www.cadstudio.cz  www.cadforum.cz

 

Message 4 of 6

Kent1Cooper
Consultant
Consultant

Deleting spaces is easy, with certain (vl-string...) functions, but your situation is complicated by the fact that 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?  If the answer to both of those questions is Yes, something could probably be worked out.

Kent Cooper, AIA
0 Likes
Message 5 of 6

chaitanya.chikkala
Enthusiast
Enthusiast

ATTACHED LISP FILE MAY HELP YOU...

 

COMMAND TO USE : "REMOVE_SPACE"

 

 

 

THANKS & REGARDS,

CHAITANYA.

0 Likes
Message 6 of 6

Kent1Cooper
Consultant
Consultant

@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
0 Likes