Howto remove Diacritics in .Net

1 minute read Published:

If you need to remove diacritics from a string you can do a lot’s of replace like this :

inputString = inputString.Replace('À', 'A');

repeat for ÀÁÂÃÄâãäàáÈÉÊËêëèéÌÍÎÏîïìíÒÓÔÖôõöòóÙÚÛÜûüùúÝýÑñç and maybe miss some exotic chars or the Õ in this list !

or you can use this function

public static string RemoveDiacritics(string inputString)
	{
		//!\\ Warning 'œ' will be replaced with a 'o' not an 'oe'
		String normalizedString = inputString.Normalize(NormalizationForm.FormD);
		StringBuilder stringBuilder = new StringBuilder();
		for (int i = 0; i < normalizedString.Length; i++)
		{
			Char c = normalizedString[i];
			if (System.Globalization.CharUnicodeInfo.GetUnicodeCategory(c) != System.Globalization.UnicodeCategory.NonSpacingMark)
				stringBuilder.Append(c);
		}
		return stringBuilder.ToString();
	}
comments powered by Disqus