TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: Adesu on March 22, 2007, 10:08:28 PM

Title: Where my xxx
Post by: Adesu on March 22, 2007, 10:08:28 PM
(setq xx "xxx_x")                ; "xxx_x"
(vl-string-right-trim "_x" xx)   ; ""    >>>????
Title: Re: Where my xxx
Post by: JohnK on March 22, 2007, 10:12:08 PM
My dog ate it!
Title: Re: Where my xxx
Post by: dan19936 on March 22, 2007, 10:18:57 PM
vl-string-right-trim will remove each individual character in the list provided, not the string pattern, meaning it removes each "_" and each "x" it finds, not the pattern "_x"
Title: Re: Where my xxx
Post by: Kerry on March 22, 2007, 10:19:34 PM
yes, it happens to be recursive ..

(setq xx "a1212121212")                
(vl-string-right-trim "12" xx)
;;-> "a"

(setq xx "a12                    ")                
(vl-string-right-trim " " xx)
;;-> "a12"

(setq xx "a1212121212p")                
(vl-string-right-trim "12a" xx)
;;-> "a1212121212p"


(setq xx "a1212121212p")                
(vl-string-right-trim "12ap" xx)
;;-> ""

(setq xx "a1212121212")                
(vl-string-right-trim "12324555a453" xx)
;;-> ""
Title: Re: Where my xxx
Post by: Kerry on March 22, 2007, 10:42:04 PM
you could try something like this ..
Code: [Select]
(SETQ
   string    "xxx_x"
   pattern   "_x"
   newString (IF (SETQ index (VL-STRING-SEARCH pattern string 0))
                (VL-STRING-SUBST "" pattern string index)
             )
)
Title: Re: Where my xxx
Post by: Adesu on March 22, 2007, 11:05:25 PM
Great info,this would memorized in my brain,thanks.

vl-string-right-trim will remove each individual character in the list provided, not the string pattern, meaning it removes each "_" and each "x" it finds, not the pattern "_x"
Title: Re: Where my xxx
Post by: Adesu on March 22, 2007, 11:09:53 PM
Good solution,thanks for your help.

you could try something like this ..
Code: [Select]
(SETQ
   string    "xxx_x"
   pattern   "_x"
   newString (IF (SETQ index (VL-STRING-SEARCH pattern string 0))
                (VL-STRING-SUBST "" pattern string index)
             )
)
Title: Re: Where my xxx
Post by: Kerry on March 22, 2007, 11:24:25 PM
be aware that this will replace the first match it finds ...

a better way may be to :
count the characters in the pattern
count the characters in the string
subtract patternCount from StringCount
use that value as the last parameter in (VL-STRING-SEARCH pattern string < Count Difference > )