Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Extension method to remove accents
using System.Globalization;
using System.Text;
public static class StringExtensions
{
public static string RemoveAccents(this string textInput)
{
if (string.IsNullOrEmpty(textInput))
{
return string.Empty;
}
var sb = new StringBuilder();
var arrayText = textInput.Normalize(NormalizationForm.FormD).ToCharArray();
foreach (char letter in arrayText)
{
if (CharUnicodeInfo.GetUnicodeCategory(letter) != UnicodeCategory.NonSpacingMark)
sb.Append(letter);
}
return sb.ToString();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment