|
-
Apr 20th, 2005, 04:03 PM
#1
Thread Starter
Hyperactive Member
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
Last edited by DaveBo; Apr 21st, 2005 at 10:55 AM.
Reason: Typo
"The wise man doesn't know all the answers, but he knows where to find them."
VBForums is one place, but for the really important stuff ... here's a clue 1Tim3:15
-
Apr 21st, 2005, 10:53 AM
#2
Thread Starter
Hyperactive Member
Like operator bug
FWIW, I tried this with both Option Compare Binary and Text - no difference.
I'm convinced this is a BUG!
Not a big one maybe, but it did bite me yesterday when I copied one of my more simple and vanilla VB6 routines into a .NET program and it gave me new and wonderfully unexpected results (Never trust a computer!)
I always used to say "the best thing about computers is they can do the same task faithfully millions of times ... and 2+2 will always equal 4"
Now I long to take my PC out into a field and use my new peripheral sledge hammer on it.
Anyone see the movie "Office Space" and the copy machine "incident"?
DaveBo out
"The wise man doesn't know all the answers, but he knows where to find them."
VBForums is one place, but for the really important stuff ... here's a clue 1Tim3:15
-
Apr 21st, 2005, 12:19 PM
#3
Fanatic Member
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/
If wishes were fishes we'd all cast nets.
-
Apr 21st, 2005, 03:10 PM
#4
Addicted Member
Re: Like operator acts diff vs in VB6
There are no stupid questions, but a whole bunch of dumb sayings !
Save time on database code, try DataLG !
-
Apr 21st, 2005, 03:28 PM
#5
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.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|