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
 

emexes

Expert
Licensed User
I have gotten this far to reproducing the symptoms:
B4X:
Dim bc As ByteConverter
 
Dim Bob1 As String = "siaka" & Chr(65312) & "gmail.com"
Dim Bob2 As String = "siaka" & Chr(64) & "gmail.com"
 
Log(Bob1.Length & " " & Bob1)
Log(Bob2.Length & " " & Bob2)
Log((Bob1 = Bob2))
produces this log:

 
Upvote 0

emexes

Expert
Licensed User
This is expected. The two strings are different.
Agreed. But they look the same on my screen:



Not that it matters - my theory of different-character-same-appearance falls over when I use .CompareTo, which apparently returns a different result to using the "=" operator.
 
Upvote 0

emexes

Expert
Licensed User
Now I am thinking perhaps the one Unicode character can end up being different byte patterns, depending upon the encoding used.
 
Upvote 0

emexes

Expert
Licensed User
Upvote 0

makis_best

Well-Known Member
Licensed User
Longtime User
@Erel The EmailTxt.Text return 7369616B6140676D61696C2E636F6D And The Local_Email return 7369616B614040676D61696C2E636F6D

I think something is hidden somewhere.... I need to check the database field
 
Upvote 0

makis_best

Well-Known Member
Licensed User
Longtime User
True....

I have to find why.... for the moment I use Replace.
and I be back when I have news
 
Upvote 0

makis_best

Well-Known Member
Licensed User
Longtime User
OK.... I find it.... After that post I go to sleep... I haven't sleep all night looking what is going on.
I did 4 steps.
1) I alter database field from string to TEXT.
2) I check the code and then Log(EmailTxt.Text.Length & " " & Local_Email.Length) Return siaka@gmail.com = siaka@ gmail.com Space after @
3) I alter database field from TEXT to string.
4) I run the code again and executed correctly.
No error using If Local_Email = EmailTxt.Text Then.....

Problem solved after alter the field twice.....

Very strange!!!!!
I can understand it.
But now everything seems to work perfect.
 
Upvote 0

emexes

Expert
Licensed User
There is still the issue of why .CompareTo worked when "=" did not. You're probably right to let it go; when things are not making sense, it is easy to mix up what happened when, and simpler to let it be.

I still have a theory about character encodings that might reproduce the symptoms. You are using non-ASCII characters, which should be no problem, but... I'll keep looking for another half-hour, otherwise I won't be able to sleep all night either!

 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…