Why is it that the following evaluates as True
?
Dim result = "b" Like "*a*b"
Thanks.
EDIT:
To generalize this a bit, the following returns True
:
"String1" Like "*AnyText1*AnyText2*AnyText???******????*String1"
VBA works correctly, returning False
.
PowerShell works correctly, returning False
:
PS C:\Users\XXX> "b" -Like "*a*b"
False
EDIT2:
The link to the bug report:
https://connect.microsoft.com/VisualStudio/feedback/details/748415/a-bug-in-net-like-operator
I decided, for fun, to open up ilspy to debug this :-)
in this method;
private static void MatchAsterisk(string Source, int SourceLength, int SourceIndex, LigatureInfo[] SourceLigatureInfo, string Pattern, int PatternLength, int PatternIndex, LigatureInfo[] PattternLigatureInfo, ref bool Mismatch, ref bool PatternError, CompareInfo Comparer, CompareOptions Options)
for this condition
if (SourceLength <= 0)
{
return;
}
by changing it to
if (SourceLength < 0)
{
return;
}
it seem to be make it work as intended
I only did a few small test, nothing big
the issue is; it is only looking at the LAST asterisk and when it was valid, was stopping right there
my small change make sure to check the previous one, or anything in fact before it
with my fix
Dim result = "b" Like "*a*b"
now return false
"String1" Like "*AnyText1*AnyText2*AnyText???******????*String1"
now return false
but does return true when it need to return true
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With