Like operator acts diff vs in VB6
In VB.NET using the "Like" operator to compare 2 strings gives me a different result now, as compared to in VB6.
Is this a bug?
e.g. ("aza" Like "*a*z*") = False !!!
yet, ("az" Like "*a*z*") = True (as I would expect)
Incidentally, I tried doing a search here for "Like" and the search engine didn't like that as a keyword.
Any ideas? Thanks, DaveBo
Re: Like operator acts diff vs in VB6
I've never used the like operator in either so I'm not 100% sure what the problem is but I know an easy solution. Instead of using Like use the RegEx objects.
^.a.z.$
that is the regular expression that will match *a*z* where * is any single character:
aaaza = true
baiza = true
bbaza = false
dadzdd = false
a breakdown of the expression:
^ - match beginning
. - match any single character
a - match only lowercase a
z - match only lowercase z
$ - match end
if you wanted to match both upper and lowercase you would do the following:
^.[aA].[zZ].$
Here's an excellent site on RegEx in general:
http://www.regular-expressions.info/
Re: Like operator acts diff vs in VB6
Re: Like operator acts diff vs in VB6
its the first * in the match pattern that is causing it. I don't have a reason why, it is possible to be a bug.