Author Topic: How to ssget the text with"[]" and replace it with pattern?  (Read 7718 times)

0 Members and 1 Guest are viewing this topic.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10362
Re: How to ssget the text with"[]" and replace it with pattern?
« Reply #15 on: March 07, 2009, 04:42:25 PM »
Back to the code request.

What is the string you wish to find?

What is the string you want to replace with?
I've reached the age where the happy hour is a nap. ()
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

cjw

  • Newt
  • Posts: 162
Re: How to ssget the text with"[]" and replace it with pattern?
« Reply #16 on: March 08, 2009, 12:18:36 AM »
Find string include "Wild-card characters"

For example:

1.
"300*700"

Code: [Select]
(setq pattern "`*")
(ssget (list (1  (strcat "*" pattern "*")))

replace "*" -> "x"

return: "300x700"

------------------------------
2.
"abc[123]"

Code: [Select]
(setq pattern "[`123`]")
(ssget (list (1  (strcat "*" pattern "*")))

replace "[123]"->"[456]"

return: "abc[456]"



Quote

Wild-card characters
 
Character
 Definition
 
# (pound)
 Matches any single numeric digit.
 
@ (at)
 Matches any single alphabetic character.
 
. (period)
 Matches any single nonalphanumeric character.
 
* (asterisk)
 Matches any character sequence, including an empty one, and it can be used anywhere in the search pattern: at the beginning, middle, or end.
 
? (question mark)
 Matches any single character.
 
~ (tilde)
 If it is the first character in the pattern, it matches anything except the pattern.
 
[...]
 Matches any one of the characters enclosed.
 
[~...]
 Matches any single character not enclosed.
 
- (hyphen)
 Used inside brackets to specify a range for a single character.
 
, (comma)
 Separates two patterns.
 
` (reverse quote)
 Escapes special characters (reads next character literally).
 

The slow need to start early!

FengK

  • Guest
Re: How to ssget the text with"[]" and replace it with pattern?
« Reply #17 on: March 08, 2009, 12:56:27 AM »
Find string include "Wild-card characters"

For example:

1.
"300*700"

Code: [Select]
(setq pattern "`*")
(ssget (list (1  (strcat "*" pattern "*")))

replace "*" -> "x"

return: "300x700"

------------------------------
2.
"abc[123]"

Code: [Select]
(setq pattern "[`123`]")
(ssget (list (1  (strcat "*" pattern "*")))

replace "[123]"->"[456]"

return: "abc[456]"



cjw, i'm still not following the description of your question.

To find "300*700" where "*" is the actual "*" character, we can use "300`*700" and apparently you already knew this. Similarly to find "[123]", we can use "`[123`]". I wonder if your question is how to perform the replacement for all the matching instances found.

Instead of giving examples, can you tell us what is the actual problem you're trying to solve?

cjw

  • Newt
  • Posts: 162
Re: How to ssget the text with"[]" and replace it with pattern?
« Reply #18 on: March 08, 2009, 09:41:58 AM »
Code: [Select]
;;CJW-SS-VALUE_LIST By carrot1983
(defun CJW-SS-VALUE_LIST (SS ITEM / I VALUE_LIST)
  (repeat (setq I (sslength SS))
    (setq
      VALUE_LIST
       (cons
(cdr (assoc ITEM (entget (ssname SS (setq I (1- I)))))
)
VALUE_LIST
       )
    )
  )
  VALUE_LIST
)

(defun c:tt ()
  (setq find_pattern "`[123`]")
  (setq replace_pattern "[456]")
  (setq ss (ssget (list (cons 0 "TEXT") (cons 1 "*" find_pattern "*"))))
  (foreach e (CJW-SS-VALUE_LIST ss -1)
    (setq string (cdr (assoc 1 (entget e))))
    (while (vl-string-search find_pattern string);_If find_pattern="`[123`]",always return nil.........
      (setq
string (vl-string-subst replace_pattern find_pattern string);_If find_pattern="`[123`]",always can't work.......
      )
    )
  )
)
The slow need to start early!

VovKa

  • Swamp Rat
  • Posts: 1144
  • Ukraine
Re: How to ssget the text with"[]" and replace it with pattern?
« Reply #19 on: March 08, 2009, 10:15:17 AM »
it's some kind of wildcard replacement function
Code: [Select]
(defun wcreplace_sub (Old String)
  (if (wcmatch String Old)
    (1+ (strlen String))
    (wcreplace_sub Old (substr String 1 (1- (strlen String))))
  )
)
(defun wcreplace (New Old String)
  (if (= String "")
    ""
    (if (wcmatch String (strcat Old "*"))
      (strcat New (substr String (wcreplace_sub Old String)))
      (strcat (substr String 1 1)
      (wcreplace New Old (substr String 2))
      )
    )
  )
)
(wcreplace "x" "`*" "300*700")
(wcreplace "[456]" "`[123`]" "abc[123]")
not thoroughly tested though
no support for multiple pattern conditions

CAB

  • Global Moderator
  • Seagull
  • Posts: 10362
Re: How to ssget the text with"[]" and replace it with pattern?
« Reply #20 on: March 08, 2009, 10:36:59 AM »
I've reached the age where the happy hour is a nap. ()
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

efernal

  • Newt
  • Posts: 196
e.fernal

cjw

  • Newt
  • Posts: 162
Re: How to ssget the text with"[]" and replace it with pattern?
« Reply #22 on: March 08, 2009, 11:10:20 PM »
Thank you all!!!

CAB Se7en VovKa xycadd MP Mark Thomas scottcd gskelly xycadd efernal



Here are some links that may prove useful.

2 post in this one.
http://www.theswamp.org/index.php?topic=5004.msg60485#msg60485

Link to a link.
http://www.theswamp.org/index.php?topic=5892.msg72153#msg72153



The slow need to start early!

CAB

  • Global Moderator
  • Seagull
  • Posts: 10362
Re: How to ssget the text with"[]" and replace it with pattern?
« Reply #23 on: March 09, 2009, 12:02:50 AM »
On behalf of the TEAM, you're welcome.   8-)
I've reached the age where the happy hour is a nap. ()
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

MP

  • Seagull
  • Posts: 17400
Re: How to ssget the text with"[]" and replace it with pattern?
« Reply #24 on: March 09, 2009, 06:59:04 PM »
Quote
;;;     FIND.LSP
;;;     Copyright (C) 1997 by Autodesk, Inc.
;;;
;;;     Permission to use, copy, modify, and distribute this software
;;;     for any purpose and without fee is hereby granted, provided
;;;     that the above copyright notice appears in all copies and
;;;     that both that copyright notice and the limited warranty and
;;;     restricted rights notice below appear in all supporting
;;;     documentation.

Surely so long as this is included any modification is entirely within the intent of the release of the lisp originally?

Thanks for observing and posting that Scott, I missed it completely. <facepalm>
\|// Set goal. Experiment tirelessly until
|Oo| practice has become expertise.  Loop.
|- | LinkedIn | Dropbox