I do C#, no experince with VB and I don't have any VB installed. I've been looking at the code below to understand how it works, could someone take a look at this?
So if I call this method with Cat
and cat
and don't pass the optional parameter, does it return true and says Cat
and cat
are equal?
Public Function AreStringsEqual(ByRef sString1 As String, ByRef sString2 As String, Optional ByVal eCompareMethod As VbCompareMethod = vbBinaryCompare) As Boolean
If LenB(sString1) = LenB(sString2) Then
If LenB(sString1) = 0 Then
AreStringsEqual = True
ElseIf eCompareMethod = vbBinaryCompare Then
AreStringsEqual = (InStrB(1, sString1, sString2, eCompareMethod) <> 0)
Else
AreStringsEqual = (StrComp(sString1, sString2, eCompareMethod) = 0)
End If
End If
End Function
That’s some weird code. Anyway, the default for the third argument is vbBinaryCompare
which means that "Cat"
and "cat"
will compare unequal. To have them compare equal, you’d need to pass vbTextCompare
.
Now here’s why the code is weird: it’s utterly redundant. You could just call StrComp
directly.
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