Aftertouch Posted July 12, 2017 Posted July 12, 2017 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"? Quote
ronjonp Posted July 12, 2017 Posted July 12, 2017 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") Quote
tmelancon Posted July 13, 2017 Posted July 13, 2017 Untested.. keep us posted. (setq test1 "THIS-IS-A-TEST-STRING") (if (< 7 (strlen test1)) (substr test1 1 (- (strlen test1) 7))) Also check out: https://knowledge.autodesk.com/support/autocad-for-mac/learn-explore/caas/CloudHelp/cloudhelp/2016/ENU/AutoCAD-MAC-Core/files/GUID-417600C7-1F59-4C95-B4E8-A7996F9F994F-htm.html Quote
BIGAL Posted July 13, 2017 Posted July 13, 2017 tmelancon (setq test1 "THIS-IS-A-TEST-ST") "THIS_IS-A" you do not know how long last bit of text is. Quote
Aftertouch Posted July 13, 2017 Author Posted July 13, 2017 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! Quote
Recommended Posts
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.