+ Reply to Thread
Results 1 to 8 of 8
  1. #1
    Full Member
    Using
    AutoCAD 2004
    Join Date
    Oct 2007
    Posts
    74

    Default Search and replace inside string variable?

    Registered forum members do not see this ad.

    Dos anyone know if it is possible to run a find and replace within a string variable?

    I have a string variable that holds a string that concantenates a room name, letter and material: Example: Master Bath--A--Eos Acadia.

    I am able to remove the spaces from the variable via the "trim" function:

    (setq PRINT_CNC_TEXT(trim PRINT_CNC_TEXT "BMA" ))

    What I would also like to do is replace the two dashes with a single dash. I tried the following but it didn't work:

    (subst '"--" '"-" '("PRINT_CNC_TEXT"))

    Is there a way to do this inside the variable as opposed to running a search and replace inside the drawing?

    Thank you.

    AJS

  2. #2
    Quantum Mechanic Lee Mac's Avatar
    Computer Details
    Lee Mac's Computer Details
    Operating System:
    Windows 7 Ultimate (32-bit)
    Discipline
    Multi-disciplinary
    Lee Mac's Discipline Details
    Discipline
    Multi-disciplinary
    Details
    Custom Programming / Software Customisation
    Using
    AutoCAD 2013
    Join Date
    Aug 2008
    Location
    London, England
    Posts
    15,709

    Default

    Try running this on your drawing:

    Code:
    (defun c:repDash  (/ ss tStr pos)
      (vl-load-com)
      (if (setq ss (ssget "X"
                          (list (cons 0 "TEXT,MTEXT")
                                (cons 1 "*--*")
                                (if (getvar "CTAB")
                                  (cons 410 (getvar "CTAB"))
                                  (cons 67 (- 1 (getvar "TILEMODE")))))))
        (foreach x  (mapcar 'vlax-ename->vla-object
                      (mapcar 'cadr
                        (ssnamex ss)))
          (setq tStr (vla-get-TextString x))
          (while (setq pos (vl-string-search "--" tStr))
            (setq tStr (strcat
                         (substr tStr 1 pos) (chr 45)
                           (substr tStr (+ pos 3)))))
          (vla-put-TextString x tStr))
        (princ "\n<!> No Text Found <!>"))
      (princ))
    Lee Mac Programming

    With Mathematics there is the possibility of perfect rigour, so why settle for less?

    Just another Swamper

  3. #3
    Senior Member
    Using
    Map 3D 2008
    Join Date
    Apr 2009
    Location
    The one after 909
    Posts
    402

    Default

    (if (getvar "CTAB") ... shouldn't that always return true? Is there any way for "CTAB" to be nil?

    Also, couldn't you use (vl-string-subst) instead of (strcat)?

    Sorry if I'm asking too many questions, I only just started getting into VLA like.. last week.. it's very new to me and I'm learning a lot, and quickly.

  4. #4
    Quantum Mechanic Lee Mac's Avatar
    Computer Details
    Lee Mac's Computer Details
    Operating System:
    Windows 7 Ultimate (32-bit)
    Discipline
    Multi-disciplinary
    Lee Mac's Discipline Details
    Discipline
    Multi-disciplinary
    Details
    Custom Programming / Software Customisation
    Using
    AutoCAD 2013
    Join Date
    Aug 2008
    Location
    London, England
    Posts
    15,709

    Default

    Great idea about using vl-string-subst, with so many VL functions, you sometimes forget a few

    Code:
    (defun c:repDash  (/ ss tStr)
      (vl-load-com)
      (if (setq ss (ssget "X"
                          (list (cons 0 "TEXT,MTEXT")
                                (cons 1 "*--*")
                                (if (getvar "CTAB")
                                  (cons 410 (getvar "CTAB"))
                                  (cons 67 (- 1 (getvar "TILEMODE")))))))
        (foreach x  (mapcar 'vlax-ename->vla-object
                      (mapcar 'cadr
                        (ssnamex ss)))
          (setq tStr (vla-get-TextString x))
          (while (vl-string-search "--" tStr)
            (setq tStr (vl-string-subst "-" "--" tStr)))
          (vla-put-TextString x tStr))
        (princ "\n<!> No Text Found <!>"))
      (princ))

    As for the CTAB, R14 didn't have it.
    Lee Mac Programming

    With Mathematics there is the possibility of perfect rigour, so why settle for less?

    Just another Swamper

  5. #5
    Senior Member
    Using
    Map 3D 2008
    Join Date
    Apr 2009
    Location
    The one after 909
    Posts
    402

    Default

    Ah, I see I see.. wow, that's a job itself, trying to make it all backwards compatible. I never did use R14.. just how different is it from, say, 2004, or 2008? I'd imagine it must at least have VL, but that it wouldn't have "ctab"...

  6. #6
    Quantum Mechanic Lee Mac's Avatar
    Computer Details
    Lee Mac's Computer Details
    Operating System:
    Windows 7 Ultimate (32-bit)
    Discipline
    Multi-disciplinary
    Lee Mac's Discipline Details
    Discipline
    Multi-disciplinary
    Details
    Custom Programming / Software Customisation
    Using
    AutoCAD 2013
    Join Date
    Aug 2008
    Location
    London, England
    Posts
    15,709

    Default

    Quote Originally Posted by Freerefill View Post
    Ah, I see I see.. wow, that's a job itself, trying to make it all backwards compatible. I never did use R14.. just how different is it from, say, 2004, or 2008? I'd imagine it must at least have VL, but that it wouldn't have "ctab"...
    Good point, I suppose the IF statement isn't required here as R14 didn't have VL either - I just keep the ssget code as a set block of code and copy it when I need it... need to look over it more in the future.
    Lee Mac Programming

    With Mathematics there is the possibility of perfect rigour, so why settle for less?

    Just another Swamper

  7. #7
    Full Member
    Using
    AutoCAD 2004
    Join Date
    Oct 2007
    Posts
    74

    Default

    Thank you very much!

  8. #8
    Quantum Mechanic Lee Mac's Avatar
    Computer Details
    Lee Mac's Computer Details
    Operating System:
    Windows 7 Ultimate (32-bit)
    Discipline
    Multi-disciplinary
    Lee Mac's Discipline Details
    Discipline
    Multi-disciplinary
    Details
    Custom Programming / Software Customisation
    Using
    AutoCAD 2013
    Join Date
    Aug 2008
    Location
    London, England
    Posts
    15,709

    Default

    Registered forum members do not see this ad.

    No probs, happy to help
    Lee Mac Programming

    With Mathematics there is the possibility of perfect rigour, so why settle for less?

    Just another Swamper

Similar Threads

  1. Is it Possible to search for the text inside a Dwg file??...
    By sarabrajkumar in forum CAD Management
    Replies: 26
    Last Post: 24th Dec 2008, 12:31 pm
  2. Autodesk Visual Search and Content Search available on Autodesk Labs
    By Between the Lines in forum AutoCAD RSS Feeds
    Replies: 0
    Last Post: 23rd Oct 2007, 08:30 pm
  3. Search and Replace Attribute Values
    By Lynn Allen's Blog in forum AutoCAD RSS Feeds
    Replies: 0
    Last Post: 10th May 2007, 07:50 pm
  4. Determining if I have string characters in text a variable
    By muck in forum AutoLISP, Visual LISP & DCL
    Replies: 1
    Last Post: 7th Feb 2007, 09:55 pm
  5. string text
    By brassworks in forum AutoCAD Drawing Management & Output
    Replies: 2
    Last Post: 6th Oct 2006, 03:04 pm

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts