TheSwamp
Code Red => AutoLISP (Vanilla / Visual) => Topic started by: Adesu on March 22, 2007, 10:08:28 PM
-
(setq xx "xxx_x") ; "xxx_x"
(vl-string-right-trim "_x" xx) ; "" >>>????
-
My dog ate it!
-
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"
-
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)
;;-> ""
-
you could try something like this ..
(SETQ
string "xxx_x"
pattern "_x"
newString (IF (SETQ index (VL-STRING-SEARCH pattern string 0))
(VL-STRING-SUBST "" pattern string index)
)
)
-
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"
-
Good solution,thanks for your help.
you could try something like this ..
(SETQ
string "xxx_x"
pattern "_x"
newString (IF (SETQ index (VL-STRING-SEARCH pattern string 0))
(VL-STRING-SUBST "" pattern string index)
)
)
-
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 > )