How can i match exactly the two texts in InStr
function ?
Right now my code is like below
If InStr(1, arrcallpara(i), strvarcalll) > 0 Then
blncalling = True
End If
arrcallpara(i) contains value "1234" or "12345" or "1234567" and strvarcalll contains "1234567"
The "If" condition should be satisfied only when there is exact match between arrcallpara(i) and strvarcalll.
Why use InStr
? You can easily check if 2 strings match by using the =
.
Anyway, let's say that you are somehow forced to use it, I would check first if a string is contained in the second, then if the second is contained in the first. That should do it, but to be totally sure you could also check if the lengths are equal:
If InStr(1, arrcallpara(i), strvarcalll) <> 0 And InStr(1, strvarcalll, arrcallpara(i)) <> 0 And Len(arrcallpara(i)) = Len(strvarcalll)
You could use StrComp
If StrComp(arrcallpara(i), strvarcalll) = 0 Then
or just plain old =
If arrcallpara(i) = strvarcalll Then
But more than that, your If
is unnecessary clutter. Just say:
blncalling = (arrcallpara(i) = strvarcalll)
or
blncalling = (StrComp(arrcallpara(i), strvarcalll) = 0)
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