View Full Version : Wildcard searching in IF-ELSE statements?

04 April 2009, 03:19 PM

I´m having a little problem here

Take a look at this

string $test = "test_knee_test";

if($test == "*_knee_*")
print "Yes";

else print "No";

I want it to return Yes, but it doesn´t. Shouldn´t it?

If i do a search in maya like this:
select -r ("*_knee_*");
That selects what I want ...

... so why is not the if-statement working?

// Otto

04 April 2009, 03:36 PM
because == is for exact comparison, i.e _knee_ == _knee_

if you want to use *, then use gmatch command.

if(`gmatch $test "*_knee_*"`)

04 April 2009, 05:31 PM
Thank you Jefri, great!


04 April 2009, 09:22 PM
Or use the "match" command as it will allow you to use more in depth regular expressions for hunting string matches

04 April 2009, 08:04 AM
Okey, will try that too, thanks Free4

CGTalk Moderation
04 April 2009, 08:04 AM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.