简体   繁体   中英

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?

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

Looks like just another copy-paste issue.

在此处输入图片说明

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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM