Author Topic: VL-STRING-TRIM  (Read 2563 times)

0 Members and 1 Guest are viewing this topic.

hudster

  • Gator
  • Posts: 2848
VL-STRING-TRIM
« on: September 22, 2005, 09:41:44 AM »
How can I strip out the \\mods from this directory name

Code: [Select]
"X:\\dwg\\04\\504-011-00 North Lanarkshire Schools\\A2.1 Coatbridge RC\\Mech\\current\\Mods"
I tried
Code: [Select]
(SETQ DIRNAME (GETVAR "DWGPREFIX"))
(SETQ NEWDIRNAME (VL-STRING-TRIM "\\MODS" DIRNAME))

and

Code: [Select]
(SETQ NEWDIRNAME (VL-STRING-TRIM "\\MODS" DIRNAME))
but It won't strip out the mods section of the drawing prefix.
Revit BDS 2017, 2016, 2015, 2014, AutoCAD 2017, 2016, Navisworks 2017, 2016, BIM360 Glue

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: VL-STRING-TRIM
« Reply #1 on: September 22, 2005, 09:44:20 AM »
Hint: vl-string-trim is case sensitive.
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

hudster

  • Gator
  • Posts: 2848
Re: VL-STRING-TRIM
« Reply #2 on: September 22, 2005, 09:46:23 AM »
that got it, i've been looking at that for 2 hours.... :oops: :ugly:
Revit BDS 2017, 2016, 2015, 2014, AutoCAD 2017, 2016, Navisworks 2017, 2016, BIM360 Glue

Andrea

  • Water Moccasin
  • Posts: 2372
Re: VL-STRING-TRIM
« Reply #3 on: September 23, 2005, 02:06:36 PM »
(vl-filename-directory  "X:\\dwg\\04\\504-011-00 North Lanarkshire Schools\\A2.1 Coatbridge RC\\Mech\\current\\Mods")
Keep smile...

whdjr

  • Guest
Re: VL-STRING-TRIM
« Reply #4 on: September 23, 2005, 02:41:47 PM »
You could also use (vla-get-path obj) :angel:

JohnK

  • Administrator
  • Seagull
  • Posts: 10659
Re: VL-STRING-TRIM
« Reply #5 on: September 23, 2005, 03:33:09 PM »
You can do tons of stuff to strings. (I like playing arround with them.)

Here are a few from my stuff that i found right away that you might be interisted in if you wanted to play arround more.

Code: [Select]
;;;===================================================================;
;;; instr?                                                            ;
;;;-------------------------------------------------------------------;
;;; Returns the charater position of the first occurnce               ;
;;; of the substring in the string                                    ;
;;;                                                                   ;
;;; Usage: (instr? "test" "this is a test of johns procedure" nil)    ;
;;;      > 11  (The index number of the first occurance.)             ;
;;;                                                                   ;
;;; Arguments: sstr - A sub-string to search for.                     ;
;;;            str - A string to search.                              ;
;;;            c-sen - T = case matters                               ;
;;;                    nil = Case dose not matter                     ;
;;;                                                                   ;
;;; Notes: This procedure uses recursion, so handeling a large lists  ;
;;;        is not recomemded. (you could get a stack error.)          ;
;;;                                                                   ;
;;; Author: John Kaul                                                 ;
;;;                                                                   ;
;;; Revision History:                                                 ;
;;; 0.1 - initial release                                             ;
;;; 0.2 - added case sensitivity                                      ;
;;;                                                                   ;
;;; TODO:                                                             ;
;;;      Add the option to choose case sensitivity. ~DONE~            ;
;;;===================================================================;
;;; Previous versions                                                 ;
;;;-------------------------------------------------------------------;
;;; ver 0.1                                                           ;
;;;-------------------------------------------------------------------;
;;; (defun instr? (sstr str / a)
;;;   (defun isinstr-nest (sstr str)
;;;     (cond ((> (strlen str) 0)
;;;            (if (eq sstr (substr str 1 (strlen sstr)))
;;;              str
;;;              (isinstr-nest sstr (substr str 2))))))
;;;   (setq a (isinstr-nest sstr str))
;;;   ;; if there is a good result... otherwise...
;;;   (if a (1+ (- (strlen str) (strlen a))) nil))
;;;-------------------------------------------------------------------;
;;; ver 0.2                                                           ;
;;;-------------------------------------------------------------------;
(defun instr? (sstr str c-sen / a)
  (cond ((eq c-sen nil) (setq sstr (strcase sstr))
               (setq str (strcase str))))
  ;; if the user wants case sensivity then set the str's
  ;; case to upper, otherwise dont evaluate (less steps)
  (defun instr-nest (sstr str)
    (cond ((> (strlen str) 0)
           ;; If there is still more string to search
           (if (eq sstr (substr str 1 (strlen sstr)))
           ;; Check the substring with a part of the string
           ;; to see if they match if they do...
             str ; Return the string
             (instr-nest sstr (substr str 2)))))) ; go thur again
  (setq a (instr-nest sstr str)) ; Set a variable for testing
  ;; if there is a good result... otherwise...
  (if a (1+ (- (strlen str) (strlen a))) nil))

Code: [Select]
;; Take a given string and strip it to the point where you want it to.
;; Pass the last charater you want removed from the string.
;; e.g. (StringStrip-Begining "This is a test" "i")
;;   -> "s a test"
(defun StringStrip-Begining (Str Char)
  (defun ListStriper (lst dec)
   (if (= (car lst) dec)
     (cdr lst) (ListStriper (cdr lst) dec)))
       (cond ((wcmatch str (strcat "*"char"*"))
         (vl-List->String
           (ListStriper
             (StrList->DecList
               (String->StrList str)) (ascii Char))))))
;;;                                                                   ;
;;; e.g. (StringStrip-End "This is a test" "i")
;;;   -> "This "
(defun StringStrip-End (Str Char)
  (defun ListStriper (lst dec)
    (if (= (car lst) dec)
      (cdr lst) (ListStriper (cdr lst) dec)))
       (cond ((wcmatch str (strcat "*"char"*"))
        (vl-List->String
         (reverse
           (ListStriper
            (reverse
              (StrList->AsciiList
                (String->StrList str))) (ascii Char)))))))
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

Columbia

  • Guest
Re: VL-STRING-TRIM
« Reply #6 on: September 26, 2005, 02:59:59 PM »
You could also try

Code: [Select]
(setq dir "X:\\dwg\\04\\504-011-00 North Lanarkshire Schools\\A2.1 Coatbridge RC\\Mech\\current\\Mods")
(substr dir 1 (- (strlen dir) 5))

It's just another way to skin the same rabbit.