text trimming

text trimming

nychoe1
Advocate Advocate
862 Views
6 Replies
Message 1 of 7

text trimming

nychoe1
Advocate
Advocate

(defun C:p074 (/ tmp ss itm obj str pos)
(vl-load-com)
(if (not #div#) (setq #div# "/"))
(setq tmp (getstring (strcat "\nDivisor character: <" #div# "> ")))
(if (= tmp "") (setq tmp #div#) (setq #div# tmp))
(setq ss (ssget "_:L" (list '(0 . "*TEXT") (cons 1 (strcat "*" #div# "*")))))
(if (and #div# SS)
(repeat (setq itm (sslength ss))
(setq obj (vlax-ename->vla-object (ssname ss (setq itm (1- itm)))))
(setq str (vla-get-textstring obj))
(setq pos (vl-string-position (ascii #div#) str))
(vla-put-textstring obj (substr str (+ pos 2)))
);; repeat
);if
(princ)
)

 

I got this Lisp here.
this Lisp is trim selected texts with "/"
<selected text==>result>
textL/textR ==> textR
xxx/yyy     ==>yyy
t12pty/5678  ==>5678


but I want to trim like this...

textL/textR ==> textL
xxx/yyy     ==>xxx
t12pty/5678  ==>t12pty

 

please help... thanks friends...

0 Likes
863 Views
6 Replies
Replies (6)
Message 2 of 7

Kent1Cooper
Consultant
Consultant

This line:

 

(vla-put-textstring obj (substr str (+ pos 2)))

 

is replacing the text content with what is in the original string starting with the character after the dividing character, to the end.  To start from the beginning and end with the character before the dividing character, change that line to:

 

(vla-put-textstring obj (substr str pos))

Kent Cooper, AIA
Message 3 of 7

ВeekeeCZ
Consultant
Consultant

@nychoe1 wrote:

(vla-put-textstring obj (substr str (+ pos 2)))


Change taht line to this

 

(vla-put-textstring obj (substr str 1 pos))
0 Likes
Message 4 of 7

nychoe1
Advocate
Advocate
Kent1Cooper
that is big help for me. thank you...
0 Likes
Message 5 of 7

nychoe1
Advocate
Advocate

I have a big help.

 

one more thing...

 

 

how to leave "/"

 

 

like this...

 

textL/textR ==> textL/
xxx/yyy     ==>xxx/
t12pty/5678  ==>t12pty/

 

 

0 Likes
Message 6 of 7

ВeekeeCZ
Consultant
Consultant
(vla-put-textstring obj (substr str 1 (+ pos 1)))
Message 7 of 7

nychoe1
Advocate
Advocate
I got it. thank you.
0 Likes