I had written a code where i want to compare 2 same names but one is with diacritics
eg. Dăn will match with Dan
I want to be able to match Vietnamese names with and without diacritics but my code keep returns not matching for the checking. Is there any other way to do this?
static void Main(string[] args)
{
string name1 = "Dan";
string name2 = "Dăn";
bool match = CompareStrings(name1, name2);
if (match)
{
Console.WriteLine("The strings match.");
}
else
{
Console.WriteLine("The strings do not match.");
}
}
static bool CompareStrings(string str1, string str2)
{
if (str1.Equals(str2, StringComparison.InvariantCultureIgnoreCase))
{
return true;
}
string str1Normalized = str1.Normalize(NormalizationForm.FormC);
string str2Normalized = str2.Normalize(NormalizationForm.FormC);
if (str1Normalized.Equals(str2Normalized, StringComparison.InvariantCultureIgnoreCase))
{
return true;
}
return false;
}