Author Topic: VL-STRING-RIGHT-TRIM doesnt like spaces  (Read 2678 times)

0 Members and 1 Guest are viewing this topic.

andrew_nao

  • Guest
VL-STRING-RIGHT-TRIM doesnt like spaces
« on: May 25, 2011, 10:52:54 AM »
im sure there is a better way to get what im after however my question is why doesnt this string right trim function like spaces?

example:
dname = "B-18464 SD 24 NMJM"
(setq testvar (substr dname (+ (vl-string-position (ascii " ") dname 1)))

returns
" SD 24 NMJM"

(vl-string-right-trim testvar dname)

returns
"B-1846"

im after the whole number B-18464

is there something about this function and spaces?

ronjonp

  • Needs a day job
  • Posts: 7529
Re: VL-STRING-RIGHT-TRIM doesnt like spaces
« Reply #1 on: May 25, 2011, 10:58:21 AM »
Why don't you use substr?

(setq str "B-18464 SD 24 NMJM")

(substr str 1 (vl-string-position 32 str))

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Re: VL-STRING-RIGHT-TRIM doesnt like spaces
« Reply #2 on: May 25, 2011, 11:04:01 AM »
The issue is not with spaces. The issue is with your misunderstanding of the functionality of the vl-string-right-trim function.

The string trim functions will trim all occurrences of the supplied characters from one or both sides of a string, hence the return from your test is correct since the character '4' is trimmed twice.

andrew_nao

  • Guest
Re: VL-STRING-RIGHT-TRIM doesnt like spaces
« Reply #3 on: May 25, 2011, 11:08:18 AM »
The issue is not with spaces. The issue is with your misunderstanding of the functionality of the vl-string-right-trim function.

The string trim functions will trim all occurrences of the supplied characters from one or both sides of a string, hence the return from your test is correct since the character '4' is trimmed twice.

OOOHHHHH

i thought it trimmed it once and the vl-string-trim function trimmed it twice. ill have to do a bit more reading.

thanks

andrew_nao

  • Guest
Re: VL-STRING-RIGHT-TRIM doesnt like spaces
« Reply #4 on: May 25, 2011, 11:09:52 AM »
Why don't you use substr?

(setq str "B-18464 SD 24 NMJM")

(substr str 1 (vl-string-position 32 str))

thanks for the tip
i sorta did go that route with my code but i went with ascii instead of the charater codes, why i dunno but that what i did.

thanks for your help