Substitution blank for space

Substitution blank for space

mmitchellH6TRW
Enthusiast Enthusiast
705 Views
7 Replies
Message 1 of 8

Substitution blank for space

mmitchellH6TRW
Enthusiast
Enthusiast

I am trying to replace string " " with "" : delete all spaces in the string.

 

(setq 
cable_count "1-7XD;\\P 1608AA,156;\\P 1608AA,P0156:7-8;11-12XD;\\P 1608AA,P0156:S7,1-3;\\P16-24XD"
cable_count (vl-string-subst "" " " cable_count)
)

 

0 Likes
Accepted solutions (1)
706 Views
7 Replies
Replies (7)
Message 2 of 8

paullimapa
Mentor
Mentor

vl-string-subst only will replace the first instance so use vl-string-translate instead

Also your string value though all looks like spaces they may not be

so I manually deleted the space and then used space bar on the cable_count and then this works:

(setq 
cable_count "1-7XD;\\P 1608AA,156;\\P 1608AA,P0156:7-8;11-12XD;\\P 1608AA,P0156:S7,1-3;\\P16-24XD"
cable_count (vl-string-translate " " "-" cable_count)
)

 

paullimapa_0-1685681770476.png

 


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
0 Likes
Message 3 of 8

komondormrex
Mentor
Mentor
Accepted solution

could be done with to list and back converting

(setq cable_count "1-7XD;\\P 1608AA,156;\\P 1608AA,P0156:7-8;11-12XD;\\P 1608AA,P0156:S7,1-3;\\P16-24XD"
	  cable_count (vl-list->string (vl-remove 32 (vl-string->list cable_count)))
)
Message 4 of 8

mmitchellH6TRW
Enthusiast
Enthusiast

Thank you for your insight:

(setq cable_count "1-7XD;\\P 1608AA,156;\\P 1608AA,P0156:7-8;11-12XD;\\P 1608AA,P0156:S7,1-3;\\P16-24XD"
      cable_count (vl-string-translate " " "" cable_count)
)

Does not work, (I need the the spaces eliminated, not replaced.) and my version of your code fails. 
Is there a nil character that I can replace it with? 

0 Likes
Message 5 of 8

mmitchellH6TRW
Enthusiast
Enthusiast
Thank you. This works.
0 Likes
Message 6 of 8

mmitchellH6TRW
Enthusiast
Enthusiast

Unfortunately, when implemented, pasting the text without spaces back into the multiline attribute, it replaced the \\P with <carriage return> <space>. I don't think it is fixable with lisp.
Still any ideas would be appreciated.

Problem in whole:
How to delete all spaces out of a multiline attribute, in all inserts of a block, programmatically.

 

0 Likes
Message 7 of 8

komondormrex
Mentor
Mentor

could you show how do you perform pasting back a spacefree string to multiline attribute? i have modeled the situation and it worked just fine.

0 Likes
Message 8 of 8

mmitchellH6TRW
Enthusiast
Enthusiast
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;  (replacetagvalue tag newvalue ent)		
;; tag - the attribute name
;; newvalue - the new value for that attribute
;; ent - the ent name of the entity
;; returns T if change is made 
;; else returns nil
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defun replacetagvalue (tag newvalue ent / elist) 
  (if (and (assoc 66 (setq elist (entget ent)))) 
    (progn 
      (setq ent   (entnext ent)
            elist (entget ent)
      )
      (while 
        (not 
          (or 
            (= (cdr (assoc 0 elist)) "SEQEND")
            (= (cdr (assoc 2 elist)) tag)
          )
        )
        (setq ent   (entnext ent)
              elist (entget ent)
        )
      )
    )
  )
  (if (= (cdr (assoc 0 elist)) "SEQEND") 
    nil
    (progn (setq elist (entget ent)) 
           (setq elist (subst (cons 1 newvalue) (assoc 1 elist) elist))
           (entmod elist)
           T
    )
  )
);;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;  (gettagvalue tag ent)		
;; tag - the attribute name
;; ent - the ent name of the entity
;; returns attribute value if not ""
;; else returns nil
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defun gettagvalue (tag ent / elist) 
  (if (and (assoc 66 (setq elist (entget ent)))) 
    (progn 
      (setq ent   (entnext ent)
            elist (entget ent)
      )
      (while 
        (not 
          (or 
            (= (cdr (assoc 0 elist)) "SEQEND")
            (= (cdr (assoc 2 elist)) tag)
          )
        )
        (setq ent   (entnext ent)
              elist (entget ent)
        )
      )
    )
  )
  (if (= (cdr (assoc 0 elist)) "SEQEND") 
    nil
    (progn 
      (setq elist (entget ent)
            elist (reverse elist)
      )
      (cdr (assoc 1 elist))
    )
  )
)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; DCS to Delete Cable block Spaces		Didn't get this to work
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defun c:DCS (/ fiber_cable_ss i cable_count) 
  (setq fiber_cable_ss (ssget "_X" '((2 . "FIBER_CABLE"))))
  (sssetfirst nil fiber_cable_ss)
  (repeat (setq i (sslength fiber_cable_ss)) 
    (if 
      (setq cable_count (gettagvalue 
                          "CABLE_COUNT"
                          (ssname fiber_cable_ss (setq i (1- i)))
                        )
      )
      (progn 
        (setq cable_count (vl-list->string 
                            (vl-remove 32 (vl-string->list cable_count))
                          )
        )
        (replacetagvalue "CABLE_COUNT" cable_count (ssname fiber_cable_ss i))
      )
    )
  )
  (setq fiber_cable_ss nil)
  (princ)
)
(princ "\nDCS to Delete Cable block Spaces")

FIBER_CABLE is a block with among other data attributes CABLE_COUNT.
a default for CABLE_COUNT was "1-7XD;\\P 1608AA,156;\\P 1608AA,P0156:7-8;11-12XD;\\P 1608AA,P0156:S7,1-3;\\P16-24XD"

For some reason our ACAD to GIS conversation tool was having trouble with the spaces (and perhaps the \P) but when the spaces were deleted it was fine. I delete the spaces out of the block and the sample inserts in the template. And was trying to write a lisp to process previous production work.
Since then the spaces have "reappeared" in work that my drafters had cleaned of spaces.
I am thinking now that it is a function of multiline attributes.

This DCS is just as simple as choose a FIBER_CABLE block. Select similar. Find [Find " "] [Replace ""] <replace all>.

0 Likes