Android Question Bug? Error comparing two strings

makis_best

Well-Known Member
Licensed User
Longtime User
Hi

I try to compare a string with the content of one EditText
But the code refuse to continuous inside If / End If
The result of the Log is correct as you can see below.

Why?

B4X:
Dim EmailTxt As EditText
Dim Local_Email As String
Log(EmailTxt.Text & " = " & Local_Email)
If EmailTxt.Text = Local_Email Then
    Wait For (CallSub(Me, "ChangePass")) Complete (Result As Boolean)
        ........
End If
 

makis_best

Well-Known Member
Licensed User
Longtime User
I don't understand why .CompareTo was working and "=" doesn't.
The test show that it was a difference between strings.... the normal will be .CompareTo and "=" not to work.
 
Upvote 0

agraham

Expert
Licensed User
Longtime User
'CompareTo' and 'equals' ('=') are not the same, although in most cases the result will be the same. 'equals' checks that two strings are the same length and have identical characters in each character position. 'CompareTo' compares two strings lexicographically and returns 0 if they would both have the same position in a sorted list. If you do find a case where 'CompareTo' returns 0 but 'equals' False then you would need to examine the actual Java code for 'CompareTo' to see why they are lexicographically identical.

If you do have a concrete example of lexicographical equivalence but not of strict equality then perhaps we could have a poke around and find out why.
 
Upvote 0
Top