Jump to content

How to use wildcards in Text Strings


Recommended Posts

Posted

 
(if (= (strcase txt) "AC")
   (setq txt "PV")
 )

 

When the raw discription of the point matches AC then this will set a text entitiy of PV. My problem is that this will only work if the text string matches word for word. Is there a way to word this so that I can use a wildcard.. Say for example any text string that contains AC set txt to equal PV.

 

Examples ED AC, AC GB, AC, etc these would all need to equal PV

 

I am using Autocad Landdesktop 2006, I am not very good at this lisp stuff any help would be appreciated.

Posted

Maybe...

 

(setq txt "externalgboundary") ;; this one contains GB

(setq txt (if (wcmatch (strcase txt) "*ED*,*AC*,*GB*") "PV" txt))

"PV"

 

But wait for the lisp masters... and on the mean time have a look about 'wcmatch'

 

HTH

Posted

Have a look at wcmatch function

 

(if (wcmatch (strcase txt) "*AC*")

...

 

OOps Same with LE's post above

Posted
 
(if (= (strcase txt) "AC")
   (setq txt "PV")
 )

When the raw discription of the point matches AC then this will set a text entitiy of PV. My problem is that this will only work if the text string matches word for word. Is there a way to word this so that I can use a wildcard.. Say for example any text string that contains AC set txt to equal PV.

 

Examples ED AC, AC GB, AC, etc these would all need to equal PV

 

I am using Autocad Landdesktop 2006, I am not very good at this lisp stuff any help would be appreciated.

 

If you know regex (grep) you will be fine. As commented above the wcmatch function is your best bet but regex style expressions can be used in selection sets

 

ollie

Posted
But wait for the lisp masters....

 

But you had already arrived... :P

Posted

One more:

(if (vl-string-search "AC" (strcase txt))
   (setq txt "PV")
)

  • 4 years later...
Posted

I'm new to lisp routines and trying to use wildcard in lisp to rename bunch of Text Style names and change a common part of them (similar to find & Replace, but can't get it to work. Maybe I'm doing something wrong?

 

For example, I have Text Style names something like:

T10206-UC07-P0ZEN-110001-R7A-WIP$0$_HZTXT

T10206-UC07-P0ZEN-110001-R7A-WIP$0$ARIAL

T10206-UC07-P0ZEN-110001-R7A-WIP$0$GHS

T10206-UC07-P0ZEN-110001-R7A-WIP$0$HG

 

And I want to remove the "T10206-UC07-P0ZEN-110001-R7A-WIP$0$"

_HZTXT

ARIAL

GHS

HG

 

or atlest change this sh#t to something meaningful i.e. "Old"

Old_HZTXT

Old ARIAL

Old GHS

Old HG

This is what I have written so far (ok, :? :oops: this may look stupid… but as I told you I’m new to lisps ):

 

(setq txtStyleName (tblobjname "style" (if (wcmatch (strcase txt) "T10206-UC07-P0ZEN-110001-R7A-WIP$0$*"))"))

(if (/= txtStyleName nil)

(command "-RENAME" "Style" "txtStyleName" ""))

OR

 

(setq txtStyleName (tblobjname "style" (if (wcmatch (strcase txt) "T10206-UC07-P0ZEN-110001-R7A-WIP$0$*"))"))

(if (/= txtStyleName nil)

(command "-RENAME" "Style" "txtStyleName" "Old"))

 

But none of these works.. :twisted::twisted:

Posted

Something like this perhaps

(while (setq St (tblnext "STYLE" (null St)))
 (setq StLst (cons (strcase (cdr (assoc 2 St))) StLst))
);; while
(foreach st StLst
 (if (wcmatch st "T10206-UC07-P0ZEN-110001-R7A-WIP$0$*")
   (progn
     (setq i 0)
     (while (setq pos (vl-string-search "$" st i))
(setq i (1+ pos))
     );; while
     (setq newst (substr st (1+ i)))
     (command "-RENAME" "Style" st (strcat "Old " newst))
   );; progn
 );; if
);; foreach

 

HTH

Henrique

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...