findstring

Discussion in 'AutoCAD' started by Marcel Janmaat, Oct 12, 2004.

  1. I've written this to find a part of text within a string;

    (defun findstring (fnd str / tel val)
    (setq fnd (strcase fnd) str (strcase str) tel 1)
    (while (and tel (/= str ""))
    (if (= (substr str tel (strlen fnd)) fnd)
    (setq val tel tel nil)
    (if (= tel (strlen str))
    (setq tel nil val nil)
    (setq tel (1+ tel))
    ) )
    ) (eval val)
    )

    Might there already be a command for this?

    M
     
    Marcel Janmaat, Oct 12, 2004
    #1
  2. Marcel Janmaat

    Jürg Menzi Guest

    Hi Marcel

    See 'vl-string-search' in my previous answer...

    Cheers
     
    Jürg Menzi, Oct 12, 2004
    #2
  3. Likewise, FIND.
     
    Kent Cooper, AIA, Oct 12, 2004
    #3
  4. I'm. talking about lisp here!

     
    Marcel Janmaat, Oct 12, 2004
    #4
  5. wcmatch
     
    Alan Henderson @ A'cad Solutions, Oct 12, 2004
    #5
  6. Marcel Janmaat

    CAB2k Guest

    Code:
      (defun search (fn st strt / hit rtn)
    (setq hit (vl-string-search (strcase fn) (strcase st) strt))
    (if hit
    (setq rtn (cons hit (search fn st (1+ hit))))
    '()
    )
    )
    (cond ((> (length (setq rtn (search fnd str 0))) 0) rtn) (nil))
    )
    
    
    (defun c:test (/ fnd str)
    (setq str "the cat found a intricate path")
    (princ "\nx -> ")
    (princ (setq hits (findstring "x" str)))
    (princ "\ncat -> ")
    (princ (setq hits (findstring "cat" str)))
    (princ "\nth -> ")
    (princ (setq hits (findstring "th" str)))
    (princ "\nth -> ")
    (princ (setq hits (findstring "a" "aaaaa")))
    (princ)
    )
     
    CAB2k, Oct 13, 2004
    #6
  7. Forgot about this one.
    Why reinvent the wheel right?
     
    Marcel Janmaat, Oct 13, 2004
    #7
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.
Similar Threads
There are no similar threads yet.
Loading...