Over a million developers have joined DZone.

Removing Accents In NET 2.0 With C#

·
Removing accents in NET 2.0


static string UrlSanitize(string url)
{
	url = Regex.Replace(url, @"\s+", "-");
	string stFormD = url.Normalize(NormalizationForm.FormD);
	StringBuilder sb = new StringBuilder();
 
	for (int ich = 0; ich < stFormD.Length; ich++)
	{
		UnicodeCategory uc = CharUnicodeInfo.GetUnicodeCategory(stFormD[ich]);
		if (uc != UnicodeCategory.NonSpacingMark)
		{
			sb.Append(stFormD[ich]);
		}
	}
 
	return (sb.ToString());
}
Topics:

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}