Skip to content

Instantly share code, notes, and snippets.

@akhansari
Created June 27, 2023 14:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save akhansari/65d89cb0e047a197e7ddede06f018cce to your computer and use it in GitHub Desktop.
Save akhansari/65d89cb0e047a197e7ddede06f018cce to your computer and use it in GitHub Desktop.
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