Cylis0509 Posted November 9, 2016 Posted November 9, 2016 Hi everyone, So I have LISP I am trying to modify. The code below is a snippet from there. Right now I have a dialog (dcl) and when you select from a drop down it populates a list with the name of the slides in that folder and removes the .sld. Which is good but I also need it to remove the first 22 characters from the slide name. Every slide starts with a 19 character ID followed by a space dash space, written description and description varies in length. Slide name example: 1234-5678-9101-2345 – Written Description(length varies) So in my list it should show only: Written Description(length varies) I am also looking for the inverse of this as well. I have another section which has a boxed column with a label and I need that text to be only the first 19 characters from the slide name. So my label should look like this using the same example above: 1234-5678-9101-2345 Any help would be greatly appreciated. (defun subcat_action (val) (if (/= val nil) (progn (if (setq blklst (vl-directory-files (strcat projectpath-sub "\\"(nth (read (get_tile "subcat")) subcatlst)"\\") "*.sld")) (progn (setq blkstmp ()) (foreach n blklst (setq blkstmp (append blkstmp (list (vl-string-right-trim ".sld" n))))) (mode_tile "blknm" 0) (start_list "blknm") (mapcar 'add_list blkstmp) (end_list) (set_tile "blknm" "0") (setq val3 "0") (blknm_action "0") ) (progn (setq blkstmp (list " No Details found ! ")) (start_list "blknm") (mapcar 'add_list blkstmp) (end_list) ))))) Quote
tombu Posted November 9, 2016 Posted November 9, 2016 (substr n 1 19) and (substr n 23) should give you the slide name and the description respectively. Quote
Roy_043 Posted November 9, 2016 Posted November 9, 2016 (substr "abc - def" 1 3) => "abc" (substr "abc - def" 7) => "def" If the position of " - " is variable you can find it using: (vl-string-search " - " "abc - def") => 3 Note: substr is one-based (first character is index 1), vl-string-search is zero-based. Quote
Lee Mac Posted November 9, 2016 Posted November 9, 2016 (defun SlideID ( sld ) (substr sld 1 19)) (defun SlideDescription ( sld ) (substr (vl-filename-base sld) 23)) _$ (setq sld "1234-5678-9101-2345 – Written Description(length varies).sld") "1234-5678-9101-2345 – Written Description(length varies).sld" _$ (SlideID sld) "1234-5678-9101-2345" _$ (SlideDescription sld) "Written Description(length varies)" ( EDIT: too slow ) Quote
Cylis0509 Posted November 9, 2016 Author Posted November 9, 2016 (defun SlideID ( sld ) (substr sld 1 19)) (defun SlideDescription ( sld ) (substr (vl-filename-base sld) 23)) _$ (setq sld "1234-5678-9101-2345 – Written Description(length varies).sld") "1234-5678-9101-2345 – Written Description(length varies).sld" _$ (SlideID sld) "1234-5678-9101-2345" _$ (SlideDescription sld) "Written Description(length varies)" ( EDIT: too slow ) This looks great Lee and makes sense. I am just not sure how to incorporate into existing code. This is not my original code. I am modifying someone else's. Don't want to muck it up. 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.