makis_best Well-Known Member Licensed User Longtime User Jul 10, 2019 #1 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. [email protected] = [email protected] Click to expand... Why? Code: Copy 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
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. [email protected] = [email protected] Click to expand... Why? Code: Copy 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 Jul 11, 2019 #21 I convert both strings to Unicode for checking and I be back Upvote 0
E emexes Expert Licensed User Longtime User Jul 11, 2019 #22 I have gotten this far to reproducing the symptoms: Code: Copy 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
I have gotten this far to reproducing the symptoms: Code: Copy 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:
Erel B4X founder Staff member Licensed User Longtime User Jul 11, 2019 #23 What is the output of: Code: Copy Dim bc As ByteConverter Log(bc.HexFromBytes(Text1.GetBytes("UTF8")) Log(bc.HexFromBytes(Text2.GetBytes("UTF8")) Upvote 0
What is the output of: Code: Copy Dim bc As ByteConverter Log(bc.HexFromBytes(Text1.GetBytes("UTF8")) Log(bc.HexFromBytes(Text2.GetBytes("UTF8"))
Erel B4X founder Staff member Licensed User Longtime User Jul 11, 2019 #24 emexes said: I have gotten this far to reproducing the symptoms Click to expand... This is expected. The two strings are different. Upvote 0
emexes said: I have gotten this far to reproducing the symptoms Click to expand... This is expected. The two strings are different.
E emexes Expert Licensed User Longtime User Jul 11, 2019 #25 Erel said: This is expected. The two strings are different. Click to expand... 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
Erel said: This is expected. The two strings are different. Click to expand... 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.
Erel B4X founder Staff member Licensed User Longtime User Jul 11, 2019 #26 emexes said: when I use .CompareTo, which apparently returns a different result to using the "=" operator Click to expand... Are you sure? Can you post an example? Upvote 0
emexes said: when I use .CompareTo, which apparently returns a different result to using the "=" operator Click to expand... Are you sure? Can you post an example?
E emexes Expert Licensed User Longtime User Jul 11, 2019 #27 Now I am thinking perhaps the one Unicode character can end up being different byte patterns, depending upon the encoding used. Upvote 0
Now I am thinking perhaps the one Unicode character can end up being different byte patterns, depending upon the encoding used.
Erel B4X founder Staff member Licensed User Longtime User Jul 11, 2019 #28 Strings are not affected by encodings. Strings = list of unicode code points. Encoding is relevant when you convert the code points to bytes. Upvote 0
Strings are not affected by encodings. Strings = list of unicode code points. Encoding is relevant when you convert the code points to bytes.
E emexes Expert Licensed User Longtime User Jul 11, 2019 #29 Erel said: Are you sure? Click to expand... That made me lol: this caper has me so confused that I'm not even sure that 1+1=2 any more! Can you post an example? Click to expand... This post: https://www.b4x.com/android/forum/threads/bug-error-comparing-two-strings.107534/#post-672338 q: Did using the .CompareTo method fix the problem where it was occurring in your app? a: Yes... With the .CompareTo working fine.... Click to expand... Upvote 0
Erel said: Are you sure? Click to expand... That made me lol: this caper has me so confused that I'm not even sure that 1+1=2 any more! Can you post an example? Click to expand... This post: https://www.b4x.com/android/forum/threads/bug-error-comparing-two-strings.107534/#post-672338 q: Did using the .CompareTo method fix the problem where it was occurring in your app? a: Yes... With the .CompareTo working fine.... Click to expand...
makis_best Well-Known Member Licensed User Longtime User Jul 11, 2019 #30 @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
@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
Erel B4X founder Staff member Licensed User Longtime User Jul 11, 2019 #31 The proper way to continue is by waiting for the output of the code in post #23. Upvote 0
Erel B4X founder Staff member Licensed User Longtime User Jul 11, 2019 #32 7369616B6140676D61696C2E636F6D 7369616B614040676D61696C2E636F6D There is an extra non-printable character here. You can remove it with: Code: Copy Text2 = Text2.Replace(Chr(0x04), "") Upvote 0
7369616B6140676D61696C2E636F6D 7369616B614040676D61696C2E636F6D There is an extra non-printable character here. You can remove it with: Code: Copy Text2 = Text2.Replace(Chr(0x04), "")
makis_best Well-Known Member Licensed User Longtime User Jul 11, 2019 #33 True.... I have to find why.... for the moment I use Replace. and I be back when I have news Upvote 0
E emexes Expert Licensed User Longtime User Jul 11, 2019 #34 makis_best said: @Erel The EmailTxt.Text return 7369616B6140676D61696C2E636F6D And The Local_Email return 7369616B614040676D61696C2E636F6D Click to expand... There's your problem, then: Code: Copy 7369616B6140 676D61696C2E636F6D 7369616B614040676D61696C2E636F6D I think something is hidden somewhere.... Click to expand... Agreed. Upvote 0
makis_best said: @Erel The EmailTxt.Text return 7369616B6140676D61696C2E636F6D And The Local_Email return 7369616B614040676D61696C2E636F6D Click to expand... There's your problem, then: Code: Copy 7369616B6140 676D61696C2E636F6D 7369616B614040676D61696C2E636F6D I think something is hidden somewhere.... Click to expand... Agreed.
E emexes Expert Licensed User Longtime User Jul 11, 2019 #35 Erel said: 7369616B6140676D61696C2E636F6D 7369616B614040676D61696C2E636F6D There is an extra non-printable character here. Click to expand... Actually, it is an extra printable character '@' But why is the double "@@" not displayed? Hmm. Upvote 0
Erel said: 7369616B6140676D61696C2E636F6D 7369616B614040676D61696C2E636F6D There is an extra non-printable character here. Click to expand... Actually, it is an extra printable character '@' But why is the double "@@" not displayed? Hmm.
Erel B4X founder Staff member Licensed User Longtime User Jul 11, 2019 #36 0x04 is not a printable character. You can test it with: Code: Copy Log("a" & Chr(0x04) & "b") 'ab It is a control character (EOT): https://unicode.org/charts/PDF/U0000.pdf Upvote 0
0x04 is not a printable character. You can test it with: Code: Copy Log("a" & Chr(0x04) & "b") 'ab It is a control character (EOT): https://unicode.org/charts/PDF/U0000.pdf
E emexes Expert Licensed User Longtime User Jul 11, 2019 #37 Erel said: 0x04 is not a printable character. You can test it with: Code: Copy Log("a" & Chr(0x04) & "b") 'ab It is a control character: https://www.utf8-chartable.de/unicode-utf8-table.pl Click to expand... Agreed, but the ...04... in the hex dump is not on a 2-hex-digit byte boundary. Upvote 0
Erel said: 0x04 is not a printable character. You can test it with: Code: Copy Log("a" & Chr(0x04) & "b") 'ab It is a control character: https://www.utf8-chartable.de/unicode-utf8-table.pl Click to expand... Agreed, but the ...04... in the hex dump is not on a 2-hex-digit byte boundary.
E emexes Expert Licensed User Longtime User Jul 11, 2019 #38 Code: Copy 7369616B6140 676D61696C2E636F6D 7369616B614040676D61696C2E636F6D Upvote 0
makis_best Well-Known Member Licensed User Longtime User Jul 11, 2019 #39 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 [email protected] = 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
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 [email protected] = 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.
E emexes Expert Licensed User Longtime User Jul 11, 2019 #40 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
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!