Author Topic: wcmatch returning wrong output  (Read 1659 times)

0 Members and 1 Guest are viewing this topic.

vincent.r

  • Newt
  • Posts: 101
wcmatch returning wrong output
« on: August 28, 2023, 09:12:50 AM »
Command: (wcmatch "[XX]" "*]*")
T

Command: (wcmatch "[XX]" "*]")
T

Command: (wcmatch "[XX]" "*[*")
nil

Command: (wcmatch "[XX]" "[*")
nil


Why wcmatch function returning nil ?

JohnK

  • Administrator
  • Seagull
  • Posts: 10661
Re: wcmatch returning wrong output
« Reply #1 on: August 28, 2023, 09:21:55 AM »
Brackets are a special character for the wcmatch function so you need to escape them with a backtick.

Command: (wcmatch "[XX]" "*`[*")
T
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

dexus

  • Bull Frog
  • Posts: 211
Re: wcmatch returning wrong output
« Reply #2 on: August 28, 2023, 09:22:14 AM »
This works:
Code - Auto/Visual Lisp: [Select]
  1. (wcmatch "[XX]" "`[*")

As you can see here:
https://www.theswamp.org/Sources/doc/avlisp/#wcmatch

[ is a special character, but can be escaped with a quote: `

vincent.r

  • Newt
  • Posts: 101
Re: wcmatch returning wrong output
« Reply #3 on: August 28, 2023, 09:36:44 AM »
Brackets are a special character for the wcmatch function so you need to escape them with a backtick.

Command: (wcmatch "[XX]" "*`[*")
T

Thanks JohnK. Its working.

vincent.r

  • Newt
  • Posts: 101
Re: wcmatch returning wrong output
« Reply #4 on: August 28, 2023, 09:37:33 AM »
This works:
Code - Auto/Visual Lisp: [Select]
  1. (wcmatch "[XX]" "`[*")

As you can see here:
https://www.theswamp.org/Sources/doc/avlisp/#wcmatch

[ is a special character, but can be escaped with a quote: `

Thanks dexus. Will look into it.

Lee Mac

  • Seagull
  • Posts: 12926
  • London, England
Re: wcmatch returning wrong output
« Reply #5 on: August 29, 2023, 06:47:00 AM »
You could also use vl-string-position or vl-string-search to find a character within a string - these do not accept wildcards and will therefore always treat the supplied arguments as literals.