Created
June 27, 2023 14:53
-
-
Save akhansari/65d89cb0e047a197e7ddede06f018cce to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Globalization; | |
using System.Linq; | |
using System.Text; | |
EqualsIgnoreCaseAndDiacritics("héLloṩ", "hellos"); // true | |
static string RemoveDiacritics(string str) => | |
str is null ? null : | |
string.Concat(str | |
.Normalize(NormalizationForm.FormD) | |
.Where(ch => CharUnicodeInfo.GetUnicodeCategory(ch) != UnicodeCategory.NonSpacingMark)); | |
static bool EqualsIgnoreCaseAndDiacritics(string a, string b) => | |
string.Equals(RemoveDiacritics(a), RemoveDiacritics(b), StringComparison.OrdinalIgnoreCase); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment