DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Snippets has posted 5883 posts at DZone. View Full User Profile

Removing Accents In NET 2.0 With C#

04.26.2006
| 8648 views |
  • submit to reddit
        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());
}
    

Comments

Snippets Manager replied on Fri, 2006/09/22 - 5:02am

Hello, maybe this is not c code, is csharp, it's better to use csharp label.