I am trying to compare the following two characters l and ł and get c# to return true
i.e. I have the word Przesyłka and would like to do a string comparison to Przesylka
I have tried the following but they all return false
public static void Main()
{
Console.WriteLine("l".Equals("ł", StringComparison.InvariantCulture));
Console.WriteLine("l".Equals("ł", StringComparison.Ordinal));
Console.WriteLine("l".Equals("ł", StringComparison.OrdinalIgnoreCase));
Console.WriteLine("l".Equals("ł", StringComparison.InvariantCultureIgnoreCase));
Console.WriteLine("l".Equals(RemoveDiacritics("ł"), StringComparison.InvariantCulture));
}
//https://stackoverflow.com/a/368850/2987066
static string RemoveDiacritics(string text)
{
return string.Concat(
text.Normalize(NormalizationForm.FormD)
.Where(ch => CharUnicodeInfo.GetUnicodeCategory(ch)!=
UnicodeCategory.NonSpacingMark)
).Normalize(NormalizationForm.FormC);
}
As you can see I also tried a workarond from this stackoverflow answer but it also returned false.
Is there a way to compare these two characters in c# in a way that returns true?
Try: