Author Topic: Using 'wcmatch' ...  (Read 4255 times)

0 Members and 1 Guest are viewing this topic.

Hangman

  • Swamp Rat
  • Posts: 566
Using 'wcmatch' ...
« on: June 05, 2010, 07:10:26 PM »
Hey guys,
I've been struggling with this stupid code for a couple days now, and I can't figure out why this isn't working properly.
So, I have several drawings from Microstation that have "%%129" type of fractions; "%%129", "%%131", "%%142", etc.
When these drawings are updated to our office standards, the string of text has "?" in place of the "%%129" fraction.
So I have been putting this routine together to scan the drawing and replace any text string that has the "%%" with the actual fraction.
Code: [Select]
(defun SetTextFractions (/ i AllText TextObj TextStr NewFrac
                           NewStr)
  (prompt "\nGetting all Text ... ")
  (if (setq i -1 AllText (ssget "_X" (list (cons 0 "TEXT") (cons 410 "Model"))))
    (progn
      (while
        (setq TextObj (ssname AllText (setq i (1+ i)))
              TextStr (cdr (assoc 1 (entget TextObj))))
        (prompt "\nChecking string for '%%' ... ")
        (if (wcmatch TextStr "*[%%]*")
          (cond ( (wcmatch TextStr "*[%%129]*")   ; if TextStr of 1/2" returns T
                  (setq NewFrac " 1/2")
                  (ProcessFraction)
                  (ReplaceString)
                )
                ( (wcmatch TextStr "*[%%130]*")
                  (setq NewFrac " 1/4")
                  (ProcessFraction)
                  (ReplaceString)
                )
                ( (wcmatch TextStr "*[%%131]*")
                  (setq NewFrac " 3/4")
                  (ProcessFraction)
                  (ReplaceString)
                )
                ( (wcmatch TextStr "*[%%132]*")
                  (setq NewFrac " 1/8")
                  (ProcessFraction)
                  (ReplaceString)
                )
                ( (wcmatch TextStr "*[%%133]*")
                  (setq NewFrac " 3/8")
                  (ProcessFraction)
                  (ReplaceString)
                )
                ( (wcmatch TextStr "*[%%134]*")
                  (setq NewFrac " 5/8")
                  (ProcessFraction)
                  (ReplaceString)
                )
                ( (wcmatch TextStr "*[%%135]*")
                  (setq NewFrac " 7/8")
                  (ProcessFraction)
                  (ReplaceString)
                )
                ( (wcmatch TextStr "*[%%136]*")
                  (setq NewFrac " 1/16")
                  (ProcessFraction)
                  (ReplaceString)
                )
                ( (wcmatch TextStr "*[%%137]*")
                  (setq NewFrac " 3/16")
                  (ProcessFraction)
                  (ReplaceString)
                )
                ( (wcmatch TextStr "*[%%138]*")
                  (setq NewFrac " 5/16")
                  (ProcessFraction)
                  (ReplaceString)
                )
                ( (wcmatch TextStr "*[%%139]*")
                  (setq NewFrac " 7/16")
                  (ProcessFraction)
                  (ReplaceString)
                )
                ( (wcmatch TextStr "*[%%140]*")
                  (setq NewFrac " 9/16")
                  (ProcessFraction)
                  (ReplaceString)
                )
                ( (wcmatch TextStr "*[%%141]*")
                  (setq NewFrac " 11/16")
                  (ProcessFraction)
                  (ReplaceString)
                )
                ( (wcmatch TextStr "*[%%142]*")
                  (setq NewFrac " 13/16")
                  (ProcessFraction)
                  (ReplaceString)
                )
                ( (wcmatch TextStr "*[%%143]*")
                  (setq NewFrac " 15/16")
                  (ProcessFraction)
                  (ReplaceString)
                )
                (T ; (= (wcmatch TextStr "*[%%94]*") T)
                  (setq NewFrac "%%d ")
                  (ProcessFraction)
                  (ReplaceString)
                )
          ) ; condition
        ) ; if
      ) ; while
    ) ; progn
  ) ; if
) ; EoF

(defun ProcessFraction (/ TextLen Pos Char
                          Frac PreFrac PostFrac)
  (prompt "\nProcessing Fraction ... ")
  (setq TextLen (strlen TextStr)
        Pos 1
        Char 1
  )
  (while (/= Frac "%")
    (setq Frac (substr TextStr Pos Char)) ; "8%%130\""   ; "1'-0%%129\""
    (if (/= Frac "%")
      (setq Pos (1+ Pos))   ; 1= "8", 2= "%"   ; 1= "1", 2= "'", 3= "-", 4= "0", 5= "%"
      (if (= NewFrac "%%d ") ; Else
        (setq Char (+ 3 Char))
        (setq Char (+ 4 Char)) ; Else
      ) ; if
    ) ; if
  ) ; while
  (if (> Pos 1)
    (setq PreFrac (substr TextStr 1 (1- Pos)))
    (setq PreFrac "")
  )
  (setq Frac (substr TextStr Pos Char)
        PostFrac (substr TextStr (+ Pos Char))
        NewStr (strcat PreFrac NewFrac PostFrac)
  )
) ; EoF

(defun ReplaceString (/ TextInfo)
  (prompt "\nUpdating Text string ... ")
  (entmod
    (if (assoc 1 (setq TextInfo (entget TextObj)))
      (subst (cons 1 NewStr) (assoc 1 TextInfo) TextInfo)
    )
  )
)

(defun c:Test2b (/ )
  (SetTextFractions)
  (princ)
)

The Problem I am running into is that every one of my fractions on the drawing come out as " 1/2".
So my condition is running, but it is only reading the first element of the condition with each iteration.
The 'If' statement just before the condition is so it will only run the text with the precentage symbols in the strings, not every string will have to go through the gauntlet.
Am I using 'wcmatch' inappropriately ??
Hangman  8)

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Drafting Board, Mechanical Arm, KOH-I-NOOR 0.7mm
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Jeff_M

  • King Gator
  • Posts: 4097
  • C3D user & customizer
Re: Using 'wcmatch' ...
« Reply #1 on: June 05, 2010, 07:15:53 PM »
From the (wcmatch) help:

[...]  Matches any one of the characters enclosed.

So as soon as it finds the first % it evaluates to True.

Remove the brackets and it should do what you want.

 

Hangman

  • Swamp Rat
  • Posts: 566
Re: Using 'wcmatch' ...
« Reply #2 on: June 05, 2010, 07:24:37 PM »
From the (wcmatch) help:

[...]  Matches any one of the characters enclosed.

So as soon as it finds the first % it evaluates to True.

Remove the brackets and it should do what you want.

Well, ... I'm an idiot.  I've read through that at least a dozen times.  I've (for some inconceivable reason) kept interpreting that as "... Matches all of the characters enclosed."

Thanks Jeff for setting me straight.  That indeed did the job.
Hangman  8)

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Drafting Board, Mechanical Arm, KOH-I-NOOR 0.7mm
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Using 'wcmatch' ...
« Reply #3 on: June 05, 2010, 09:44:55 PM »
I think I would do it this way:
Code: [Select]
(defun SetTextFractions (/ i AllText TextObj TextStr)
  (prompt "\nGetting all Text ... ")
  (if (setq i       -1
            AllText (ssget "_X" (list (cons 0 "TEXT") (cons 410 "Model")))
      )
      (while (setq TextObj (ssname AllText (setq i (1+ i))))
         (setq TextStr (cdr (assoc 1 (setq elst (entget TextObj)))))
         (if (vl-string-search "%%" TextStr)
           (progn
           (mapcar
             (function
               (lambda (x / elst)
                 (setq TextStr (vl-string-subst (cadr x) (car x) TextStr))
               )
             )
             '(("%%129" " 1/2")
               ("%%130" " 1/4")
               ("%%131" " 3/4")
               ("%%132" " 1/8")
               ("%%133" " 3/8")
               ("%%134" " 5/8")
               ("%%135" " 7/8")
               ("%%136" " 1/16")
               ("%%137" " 3/16")
               ("%%138" " 5/16")
               ("%%139" " 7/16")
               ("%%140" " 9/16")
               ("%%141" " 11/16")
               ("%%142" " 13/16")
               ("%%143" " 15/16")
              )
           )
           (entmod (subst (cons 1 TextStr) (assoc 1 elst) elst))
         )
      )
    )
  )
)
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.

Lee Mac

  • Seagull
  • Posts: 12921
  • London, England
Re: Using 'wcmatch' ...
« Reply #4 on: June 06, 2010, 08:07:31 AM »
Nice code Alan  8-)

One thing I would add would be that vl-string-subst only replaces the first occurrence of the string to be replaced, hence I would usually use a function like:

Code: [Select]
(defun StringSubst ( new old str )
  ;; © Lee Mac  ~  23.05.10
  (
    (lambda ( i / nl ) (setq nl (strlen new))
      (while
        (and (< i (strlen str))
          (setq i (vl-string-search old str i))
          (setq str (vl-string-subst new old str i) i (+ i nl))
        )
      )
      str
    )
    0
  )
)

In place of it  :-)

Crank

  • Water Moccasin
  • Posts: 1503
Re: Using 'wcmatch' ...
« Reply #5 on: June 06, 2010, 08:18:27 AM »
Though this it still works, %%[ASCII-code] isn't supported since Acad2006. This should be replaced with unicodes: \U+00[hexadecimal value].
Vault Professional 2023     +     AEC Collection

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Using 'wcmatch' ...
« Reply #6 on: June 06, 2010, 12:18:07 PM »
Thanks Lee, I was being lazy with my example. 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.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Using 'wcmatch' ...
« Reply #7 on: June 06, 2010, 12:43:24 PM »
Updated code.  8-)

Code: [Select]
(defun SetTextFractions (/ i AllText TextObj TextStr)
;;  CAB 11.04.07, updated 01.11.08
(defun _replace (oldtext newtext textstring / i n)
  (setq n (strlen newtext))
  (while (setq i (vl-string-search oldtext textstring i))
    (setq textstring (vl-string-subst newtext oldtext textstring i)
          i    (+ i n))
  )
  textstring
)

 
  (prompt "\nGetting all Text ... ")
  (if (setq i       -1
            AllText (ssget "_X" (list (cons 0 "TEXT") (cons 410 "Model")))
      )
      (while (setq TextObj (ssname AllText (setq i (1+ i))))
         (setq TextStr (cdr (assoc 1 (setq elst (entget TextObj)))))
         (if (vl-string-search "%%" TextStr)
           (progn
           (mapcar
             (function
               (lambda (x / elst)
                 (setq TextStr (_replace (car x) (cadr x) TextStr))
               )
             )
             '(("%%129" " 1/2")
               ("%%130" " 1/4")
               ("%%131" " 3/4")
               ("%%132" " 1/8")
               ("%%133" " 3/8")
               ("%%134" " 5/8")
               ("%%135" " 7/8")
               ("%%136" " 1/16")
               ("%%137" " 3/16")
               ("%%138" " 5/16")
               ("%%139" " 7/16")
               ("%%140" " 9/16")
               ("%%141" " 11/16")
               ("%%142" " 13/16")
               ("%%143" " 15/16")
              )
           )
           (entmod (subst (cons 1 TextStr) (assoc 1 elst) elst))
         )
      )
    )
  )
)
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.

Hangman

  • Swamp Rat
  • Posts: 566
Re: Using 'wcmatch' ...
« Reply #8 on: June 07, 2010, 04:46:34 PM »
I think I would do it this way:
Code: [Select]
(defun SetTextFractions (/ i AllText TextObj TextStr)
  (prompt "\nGetting all Text ... ")
    ...  

I am curious Alan, WHY would you do it that way ??  I mean, I know your code is superior (that's a given  :wink: ), but I am interested in what you are thinking ??  I realized I missed the possibility of having an underlined or overlined dtext (%%u or %%o) in the mix, but I don't see that as an option in your code either.  Your writing code for much longer than I, I suspect experience would push in the direction you have chosen, and that is what I am seeking with this question.


Quote from: Crank
Though this it still works, %%[ASCII-code] isn't supported since Acad2006. This should be replaced with unicodes: \U+00[hexadecimal value].
I was initially thinking to put it into Unicode, but in the end I figured it was easiest to just put it in fractional form.
Although, when you pull up the data, the DXF code 1 shows it in written fraction form, not Unicode.  So why would you want to put it in Unicode anyway ??
Hangman  8)

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Drafting Board, Mechanical Arm, KOH-I-NOOR 0.7mm
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Using 'wcmatch' ...
« Reply #9 on: June 07, 2010, 05:46:16 PM »
Well, to my eye, it is more aesthetically pleasing. :)
I chose a mapcar to step through the list replacing the characters as they are found.
My code does not repeat itself like this:
Code: [Select]
               ( (wcmatch TextStr "*[%%136]*")
                  (setq NewFrac " 1/16")
                  (ProcessFraction)
                  (ReplaceString)
                )
                ( (wcmatch TextStr "*[%%137]*")
                  (setq NewFrac " 3/16")
                  (ProcessFraction)
                  (ReplaceString)
                )
               
This is accomplished with variables and a single line of code:
Code: [Select]
(setq TextStr (_replace (car x) (cadr x) TextStr))
As for underlined or over lined dtext (%%u or %%o), what do you want to do with these?

For %%d you can add this ("%%d" "\U+0176")
and %%c use this ("%%c" "\U+0216")

Keep in mind that any code that gets the job done in a timely manor is fine with me. 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.

Lee Mac

  • Seagull
  • Posts: 12921
  • London, England
Re: Using 'wcmatch' ...
« Reply #10 on: June 07, 2010, 06:34:19 PM »
Hangman,

In your original code - what happens if the text contains more than one code?  :wink:

Hangman

  • Swamp Rat
  • Posts: 566
Re: Using 'wcmatch' ...
« Reply #11 on: June 07, 2010, 06:47:57 PM »
Well, to my eye, it is more aesthetically pleasing. :)
 ...

I agree.

Quote from: CAB
I chose a mapcar to step through the list replacing the characters as they are found.
My code does not repeat itself like this:
 ...
                
This is accomplished with variables and a single line of code:
Code: [Select]
(setq TextStr (_replace (car x) (cadr x) TextStr))

It does make it easier to read & comprehend what is happening.

Quote from: CAB
As for underlined or over lined dtext (%%u or %%o), what do you want to do with these?

For %%d you can add this ("%%d" "\U+0176")
and %%c use this ("%%c" "\U+0216")

I modified my code a touch to include, or rather exclude the underline.
Code: [Select]
...
      (while
        (setq TextObj (ssname AllText (setq i (1+ i)))
              TextStr (cdr (assoc 1 (entget TextObj))))
        (if (or (wcmatch TextStr "*%%1*")(wcmatch TextStr "*%%9*"))
          (cond ( (wcmatch TextStr ...
 ...

So for right now, I'm just searching for those text pieces with %%1 or %%9 in them.

Quote from: CAB
Keep in mind that any code that gets the job done in a timely manor is fine with me. 8-)

So as long as the housekeeper is keeping up with the mess, we're OK ?.!!  :-D    (manor vs manner)
     Sorry, couldn't resist.


I am curious about something more.
I am getting an error still:  lentityp nil
Upon the search I found that my TextObj is nil.   I have 20 pieces of text, 6 have ASCI code.  The program runs through the 6 then errors.  So all of my text with fractions is fixed, but then I get the error.
But if the program runs through all of the count 'i', then TextObj would be nil in the end.
Could the two variables in one command cause this type of problem:
Code: [Select]
     (while
        (setq TextObj (ssname AllText (setq i (1+ i)))
              TextStr (cdr (assoc 1 (entget TextObj))))
Hangman  8)

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Drafting Board, Mechanical Arm, KOH-I-NOOR 0.7mm
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Hangman

  • Swamp Rat
  • Posts: 566
Re: Using 'wcmatch' ...
« Reply #12 on: June 07, 2010, 06:50:39 PM »
Hangman,

In your original code - what happens if the text contains more than one code?  :wink:

Good question, ...
Could that be what is causing my code to error:  lentityp nil  ??
There is a piece of text with this scenario, "%%uOPEN PORT%%u"
But if your running a wildcard search, would it matter ??  "*%%u*" ...  Or does it count the string twice ??
Hangman  8)

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Drafting Board, Mechanical Arm, KOH-I-NOOR 0.7mm
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Lee Mac

  • Seagull
  • Posts: 12921
  • London, England
Re: Using 'wcmatch' ...
« Reply #13 on: June 07, 2010, 07:08:08 PM »
The error is due to your 'setq' call... bear in mind that 'setq' will return the last value bounded - think about the implications of this when using the WHILE statement.

As for my point - think about how a COND statement evaluates when it reaches a test expression that returns true.

Code: [Select]
"%%129OPENPORT%%130"

Hangman

  • Swamp Rat
  • Posts: 566
Re: Using 'wcmatch' ...
« Reply #14 on: June 07, 2010, 07:35:58 PM »
The error is due to your 'setq' call... bear in mind that 'setq' will return the last value bounded - think about the implications of this when using the WHILE statement.

You know, it really cracks me up when I see answers like this.
Not your answer, but my fault.  You see, I have other code that is formatted identically, and it works without a hitch.  I get the same thing with code that uses more than two levels deep with CAR or CDR.  For some reason (and it's just my luck), I cannot get code to work with CADDR or CADR or anything more than three characters, it always errors out on me.  I can borrow someone elses code from theSwamp, and I have to change it in order to get it to work for me.  I've just learned to accept it as 'my luck'.  It sits there next to Murphy's Law, the two are twins.  When something occurs outside of Murphy's Law, it's Hangman's Luck.  One does not trump the other, it just coincides in an opposite universe.
When I'm driving down the street, I usually get stopped at EVERY red light along my street I am travelling.  Others I know can go for miles before being stopped.  But when I ride shotgun in their car, it never fails, THEY get stopped at EVERY red light along the street.  No explanation & Murphy's law doesn't compute.  So it's Hangman's Luck.
Maybe I should change my username.  :wink:


Quote from: Lee Mac
As for my point - think about how a COND statement evaluates when it reaches a test expression that returns true.

Code: [Select]
"%%129OPENPORT%%130"

Ahh, good point indeed.  When COND runs, it runs only once to complete it's task, then goes back to the beginning of the loop.  So if two fractions are in the same string, the second is then ignored and lost because the count then increases.  Ahh Nuts!
 ...
So, off the top of my head, I'm thinking after the first search of all text and an initial cleanup, do a second search of all text.  But what if there are three fractions in the same line of text ??  So that idea isn't going to work well.
There has to be a way to search the same string of text for more than one occurance of a fraction.
 ...
I've got some thinking to do.
Hangman  8)

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Drafting Board, Mechanical Arm, KOH-I-NOOR 0.7mm
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Lee Mac

  • Seagull
  • Posts: 12921
  • London, England
Re: Using 'wcmatch' ...
« Reply #15 on: June 07, 2010, 07:42:42 PM »
You know, it really cracks me up when I see answers like this.
Not your answer, but my fault.  You see, I have other code that is formatted identically, and it works without a hitch.  I get the same thing with code that uses more than two levels deep with CAR or CDR.  For some reason (and it's just my luck), I cannot get code to work with CADDR or CADR or anything more than three characters, it always errors out on me.  I can borrow someone elses code from theSwamp, and I have to change it in order to get it to work for me.  I've just learned to accept it as 'my luck'... etc etc more waffle lol...

I'm sure you are joking here - but the beauty of programming is that everything is clean cut - the only reason it errors is because something you have entered is incorrect.. your setq statement errors because the the 'entget' will still be called when 'ssname' returns nil.

Quote from: Lee Mac
As for my point - think about how a COND statement evaluates when it reaches a test expression that returns true.

Code: [Select]
"%%129OPENPORT%%130"

Ahh, good point indeed.  When COND runs, it runs only once to complete it's task, then goes back to the beginning of the loop.  So if two fractions are in the same string, the second is then ignored and lost because the count then increases.  Ahh Nuts!

COND will evaluate the first statement in which the test expression returns true, then it will stop evaluating.
 
So, off the top of my head, I'm thinking after the first search of all text and an initial cleanup, do a second search of all text.  But what if there are three fractions in the same line of text ??  So that idea isn't going to work well.
There has to be a way to search the same string of text for more than one occurance of a fraction.

Yes, CAB has already shown you how to do it.

Hangman

  • Swamp Rat
  • Posts: 566
Re: Using 'wcmatch' ...
« Reply #16 on: June 07, 2010, 07:50:52 PM »
And then there's the issue with blocks that have these types of ASCI codes in them.
Hangman  8)

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Drafting Board, Mechanical Arm, KOH-I-NOOR 0.7mm
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Lee Mac

  • Seagull
  • Posts: 12921
  • London, England
Re: Using 'wcmatch' ...
« Reply #17 on: June 07, 2010, 07:52:17 PM »
I suppose you'll have to dig through the block definitions too  :wink:

This should help you in that respect :-)

Code: [Select]
;; GetBlockText   by Lee McDonnell   [07.05.09]
;; ARGS: Blk   ~  Block Name [Str]
;; RETURN: List of Text Entities

(defun GetBlockText ( Blk )
  (if (tblsearch "BLOCK" Blk)
    (vl-remove-if-not
      (function
        (lambda ( e ) (wcmatch (cdr (assoc 0 (entget e))) "*TEXT"))
      )
      (GetSubObjs (tblobjname "BLOCK" Blk))
    )
  )
)

(defun GetSubObjs ( e )
  (if (setq e (entnext e)) (cons e (GetSubObjs e)))
)
« Last Edit: June 07, 2010, 07:59:25 PM by Lee Mac »

Hangman

  • Swamp Rat
  • Posts: 566
Re: Using 'wcmatch' ...
« Reply #18 on: June 08, 2010, 12:02:39 PM »
Nice code Alan  8-)

One thing I would add would be that vl-string-subst only replaces the first occurrence of the string to be replaced, hence I would usually use a function like:

Code: [Select]
(defun StringSubst ( new old str )
  ;; © Lee Mac  ~  23.05.10
  (
    (lambda ( i / nl ) (setq nl (strlen new))
      (while
        (and (< i (strlen str))
          (setq i (vl-string-search old str i))
          (setq str (vl-string-subst new old str i) i (+ i nl))
        )
      )
      str
    )
    0
  )
)

In place of it  :-)

Well, ... Perhaps it is another episode of 'Hangman's Luck', but I don't think this is necessarily the case for this purpose.

I went and re-wrote Alan's code (trying to learn it) using my own variables and such (minor changes, but I'm grasping the concept of his format - very nice by the way), and ran the program.  The program cleaned up the ASCii fractions nicely.  So out of curiosity, I went and placed several ASCii fractions into one string of text and ran the code again.  It cleaned up every one of them.  So I then pulled his code from here and ran it as-is, and it cleaned up the line of text with several ASCii fractions in it.

Now from the help file we read:
Quote
Note that the search is case-sensitive, and that vl-string-subst substitutes only the first occurrence it finds of the string.
So Lee is correct, it will only substitute the first occurance.

But then why is Alan's first code post above (without the update) able to clean up multiple occurances ??  At least on my machine it's cleaning up multiple occurances within the same line of text.
Hangman  8)

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Drafting Board, Mechanical Arm, KOH-I-NOOR 0.7mm
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Lee Mac

  • Seagull
  • Posts: 12921
  • London, England
Re: Using 'wcmatch' ...
« Reply #19 on: June 08, 2010, 12:17:43 PM »
Try Alan's first code on something like:

Code: [Select]
%%130Lee%%129Mac%%130
Bear in mind that both codes are called with the same syntax, so you will need to make sure you load them before running.

Hangman

  • Swamp Rat
  • Posts: 566
Re: Using 'wcmatch' ...
« Reply #20 on: June 08, 2010, 01:23:48 PM »
Try Alan's first code on something like:
Code: [Select]
%%130Lee%%129Mac%%130Bear in mind that both codes are called with the same syntax, so you will need to make sure you load them before running.

Now this is where I get irritated.
Here's the result of your sample:
Code: [Select]
1/4Lee 1/2Mac‚
Which is:
 1/4Lee 1/2Mac%%130

And here are others I tried:
Code: [Select]
Dtext edit                 Actual text                         Results
ƒ"C, 1-2/C#18 ‚  =  %%131"C, 1-2/C#18%%129 %%130  ==>   3/4"C, 1-2/C#18 1/2  1/4

ƒ"C, "1-2/C#18†" =  %%131"C, %%129"1-2/C#18%%134"  ==>  3/4"C,  1/2"1-2/C#18 5/8"

ƒ"C, 1-2/C#18…   =  %%131"C, 1-2%%129/C#18%%133   ==>    3/4"C, 1-2 1/2/C#18 3/8

Now why is that ??  Could it be because the fraction at the end in my example is after a number and not a letter or word ??
 ...
Doht !!  I'm an idiot !!  It's catching EACH ascii fraction only once, so if I have twenty fractions, all different, in the same line of text, it'll pick them EACH up - but only once.

Gotcha !!  Now I see the light.  ggrrrrrrrr
Hangman  8)

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Drafting Board, Mechanical Arm, KOH-I-NOOR 0.7mm
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Lee Mac

  • Seagull
  • Posts: 12921
  • London, England
Re: Using 'wcmatch' ...
« Reply #21 on: June 08, 2010, 01:59:52 PM »
You got it  :wink: