Author Topic: Where my xxx  (Read 3262 times)

0 Members and 1 Guest are viewing this topic.

Adesu

  • Guest
Where my xxx
« on: March 22, 2007, 10:08:28 PM »
(setq xx "xxx_x")                ; "xxx_x"
(vl-string-right-trim "_x" xx)   ; ""    >>>????

JohnK

  • Administrator
  • Seagull
  • Posts: 10604
Re: Where my xxx
« Reply #1 on: March 22, 2007, 10:12:08 PM »
My dog ate it!
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

dan19936

  • Guest
Re: Where my xxx
« Reply #2 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"

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Where my xxx
« Reply #3 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)
;;-> ""
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Where my xxx
« Reply #4 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)
             )
)
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

Adesu

  • Guest
Re: Where my xxx
« Reply #5 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"

Adesu

  • Guest
Re: Where my xxx
« Reply #6 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)
             )
)

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Where my xxx
« Reply #7 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 > )
 
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.