2

I have the following code:

Thread.CurrentThread.CurrentCulture = new CultureInfo("vi-VN");

string a = "Biển Ðông";
string b = "Biển Đông";

if (a.Equals(b, StringComparison.CurrentCulture))
{
    Console.WriteLine("Yes");
}

The two strings are identical, but I always get false when checking using Equals. If I add this to a HashSet<string>, then I will get two items instead of one item in the container.

Thomas Ayoub
  • 29,063
  • 15
  • 95
  • 142
Benjamin Martin
  • 576
  • 1
  • 8
  • 27

3 Answers3

4

Ð is not Đ in your case.

The first "D" is the ANSI character 208 and the second one is 272.

I tested this using

(int)'Ð'
(int)'Đ'

Those are different characters which look identical, but aren't.

bytecode77
  • 14,163
  • 30
  • 110
  • 141
2

Your string are composer by the following chars:

\u0042\u0069\u1ec3\u006e \u00d0\u00f4\u006e\u0067
                            |||
\u0042\u0069\u1ec3\u006e \u0110\u00f4\u006e\u0067
Thomas Ayoub
  • 29,063
  • 15
  • 95
  • 142
0

By this logic you can find, which first character is different in strings. It might be useful in this case.

char? firstocurrenceA = string1.Zip(string2, (a, b) => new { string1 = a, string2 = b })
    .Where(x => x.string1 != x.string2)
    .Select(x => x.string1)
    .FirstOrDefault();

        char? firstocurrenceB = string1.Zip(string2, (a, b) => new { string1 = a, string2 = b })
    .Where(x => x.string1 != x.string2)
    .Select(x => x.string2)
    .FirstOrDefault();
Vivek Nuna
  • 25,472
  • 25
  • 109
  • 197