I'm working on a VB.Net application that needs to do quite a bit of string
pattern matching, and am having problems using the "LIKE" operator to match
the same string twice in the pattern. For example, in the following code:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim theString As String
theString = "1234 TEST 5432 TEST ABCD"
If theString Like "*TEST*TEST*" Then
MessageBox.Show("Matches!")
Else
MessageBox.Show("No Match!")
End If
End Sub
I would expect the LIKE operator in this test to return true, since
theString matches the pattern "*TEST*TEST*", specifying zero-or-more
characters followed by "TEST" followed by zero-or-more characters followed
by "TEST" followed by zero-or-more characters. However, when I run the above
code, the LIKE operator returns false. If I change the pattern to
"*TEST*ABC*", the LIKE operator returns true. If I alter the pattern to
something like "*TEST*TEST A*", it again returns false. It seems that LIKE
won't match a pattern that contains the same string of characters twice. Can
anyone explain why the operator behaves this way?
Thanks in advance for any replies.