C# string equality operator returns false, but I'm pretty sure it should be true… What?

偶尔善良 提交于 2019-12-05 08:36:28
Polaris878

What are the encoding types of the files you are feeding into DiffMerge? If you have characters that don't match the encoding type, then there is a chance they won't show up in DiffMerge.

The string that is being generated and the expected result probably have different character encodings. When you are doing ASCII.GetBytes, you are converting everything into ASCII. So, your strings are being converted to ASCII and are equal in terms of the ASCII character set. However, they can still be unequal in other character sets (and still "look" the same to you).

Also, try doing a string.Compare(str1, str2, StringComparison.XXXX) and let us know what happens.

Loop through char by char and find which it thinks is different? The fact that writing it to disk and comparing the ASCII / text tells me that it is probably either carriage-return / line-feed related (which is somehow normalized during save), or relates to some non-ASCII character (maybe a high-unicode whitespace), which will be stripped when saving as ASCII.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!