↓ Ir para o conteúdo principal

← todas as notas

📎 Webclip

[C#] Remove diacritics (accents) from a string

Removing diacritics from a string is a common task, and the post shows a simple extension method for doing it in .NET. The method first checks for null or whitespace, then normalizes the text, removes characters classified as non-spacing marks, and normalizes the result again.

Reading notes
#

  • The .NET framework does not have a built-in method for removing diacritics from a string.
  • Normalization Form D decomposes precomposed characters into their component code points.
  • After normalization, the method filters out code points whose Unicode category is NonSpacingMark.
  • The rebuilt string is normalized again with Normalization Form C before being returned.
  • The post explains that normalization is used here to separate accents from the input string, not to compare strings for equality.