Jump to content

Get / Remove last part of a string with '-'


Aftertouch

Recommended Posts

Hello all,

 

Im trying to find the awnser on this case...

Lets say i have a string:

(setq test1 "THIS-IS-A-TEST-STRING")

 

How can i remove the last part after the last "-", so it returns

"THIS-IS-A-TEST"?

Link to comment
Share on other sites

Hello all,

 

Im trying to find the awnser on this case...

Lets say i have a string:

(setq test1 "THIS-IS-A-TEST-STRING")

 

How can i remove the last part after the last "-", so it returns

"THIS-IS-A-TEST"?

 

(defun _choplast (del str / i)
 (substr str
  1
  (if (setq i (vl-string-position (ascii del) str 0 t))
    i
    (strlen str)
  )
 )
)
(_choplast "-" "THIS-IS-A-TEST-STRING")

Link to comment
Share on other sites

Thanks all, i used the first solution. I gues i missed this function with my reach.

When reading the AutoDesk Help of this function, it explains nicely what the code does. :-)

 

Thanks again!

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...