Last active
September 29, 2021 23:50
-
-
Save fernandezja/54428a9ac58e9e34aea9a5a287dc399f to your computer and use it in GitHub Desktop.
Extension method to remove accents
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.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