Fast string comparison
"Claus Busch" wrote:
Sub CompStrings()
Dim strA As String, strB As String
Dim i As Long
Dim myComp As Boolean
strA = "right-handed"
strB = "left-handed"
strA = Replace(Replace(strA, "-", ""), "'", "")
strB = Replace(Replace(strB, "-", ""), "'", "")
For i = 1 To Len(strA)
If LCase(Mid(strA, i, 1)) < LCase(Mid(strB, i, 1)) Then
myComp = IIf(Asc(LCase(Mid(strA, i, 1))) < _
Asc(LCase(Mid(strB, i, 1))), True, False)
MsgBox myComp
Exit For
End If
Next
End Sub
Claus, do you think it will be faster to use the "<" or "" operators
to compare strings?
For example:
strA = "left-handed"
strB = "right-handed"
if (strA < strB) then
MsgBox "True"
else
MsgBox "False"
end if
|