Jens Borrisholt
Jens Borrisholt

Reputation: 6402

Compare two strings in two different ways

I've wrote this small program in C#

private void Form1_Load(object sender, EventArgs e)
{
    MessageBox.Show(("7797302D875A8922EBFC7DECBD352FE88F35642F" == "‎7797302D875A8922EBFC7DECBD352FE88F35642F").ToString());

    var a = "7797302D875A8922EBFC7DECBD352FE88F35642F";
    var b = "7797302D875A8922EBFC7DECBD352FE88F35642F";
    MessageBox.Show((a == b).ToString());

}

First messageBox shows "False" while Messagebox shows "True".

My question is: why can I not compare the two strings with the == operator?

Upvotes: 1

Views: 125

Answers (2)

Soner Gönül
Soner Gönül

Reputation: 98868

Your second string has invisible Left-to-right mark character as (U+200E).

Looks like just another copy-paste issue.

enter image description here

Upvotes: 10

CodesInChaos
CodesInChaos

Reputation: 108880

The difference isn't caused by the comparison, but your test string strings.

The second string of the first case starts with the invisible 0x200E, the unicode left-to-right mark.

Upvotes: 3

Related Questions