Green Files

How to remove accents in a string in C#?

Day: 06/02/2022 - Time: 11:22:28

Sometimes it is needed to remove accentuation store it in the database as a URL. To solve this problem, you can use this function:

public static string RemoveAccents(this string text){ StringBuilder sbReturn = new StringBuilder(); var arrayText = text.Normalize(NormalizationForm.FormD).ToCharArray(); foreach (char letter in arrayText){ if (CharUnicodeInfo.GetUnicodeCategory(letter) != UnicodeCategory.NonSpacingMark) sbReturn.Append(letter); } return sbReturn.ToString(); }

References:

https://pt.stackoverflow.com/questions/2/como-fa%c3%a7o-para-remover-acentos-em-uma-string

http://www.ninjacode.com.br/post/2011/08/10/Retirar-acentos-de-strings-C.aspx

GO UP
GO TO INDEX