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
  • 28,235
  • 15
  • 95
  • 135
Benjamin Martin
  • 506
  • 1
  • 8
  • 24

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
  • 13,209
  • 30
  • 105
  • 134
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
  • 28,235
  • 15
  • 95
  • 135
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
  • 16,885
  • 12
  • 74
  • 152