Here is my performance, based on the answers of Joan and Marcel. The changes I made are as follows:
- Use the generally accepted method to remove accents.
- Explicit Regex caching to improve speed.
- Other word separators are recognized and normalized to hyphens.
Here is the code:
public class UrlSlugger { // white space, em-dash, en-dash, underscore static readonly Regex WordDelimiters = new Regex(@"[\sββ_]", RegexOptions.Compiled); // characters that are not valid static readonly Regex InvalidChars = new Regex(@"[^a-z0-9\-]", RegexOptions.Compiled); // multiple hyphens static readonly Regex MultipleHyphens = new Regex(@"-{2,}", RegexOptions.Compiled); public static string ToUrlSlug(string value) { // convert to lower case value = value.ToLowerInvariant(); // remove diacritics (accents) value = RemoveDiacritics(value); // ensure all word delimiters are hyphens value = WordDelimiters.Replace(value, "-"); // strip out invalid characters value = InvalidChars.Replace(value, ""); // replace multiple hyphens (-) with a single hyphen value = MultipleHyphens.Replace(value, "-"); // trim hyphens (-) from ends return value.Trim('-'); } /// See: http://www.siao2.com/2007/05/14/2629747.aspx private static string RemoveDiacritics(string stIn) { string stFormD = stIn.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().Normalize(NormalizationForm.FormC)); } }
This still does not solve the problem of the non-Latin symbol. A completely alternative solution would be to use Uri.EscapeDataString to convert the string to hexadecimal:
string original = "ζ΅θ―ε
¬εΈ"; // %E6%B5%8B%E8%AF%95%E5%85%AC%E5%8F%B8 string converted = Uri.EscapeDataString(original);
Then use the data to create the hyperlink:
<a href="http://www.example.com/100/%E6%B5%8B%E8%AF%95%E5%85%AC%E5%8F%B8">ζ΅θ―ε
¬εΈ</a>
Many browsers will display Chinese characters in the address bar (see below), but based on my limited testing, it is not fully supported.

NOTE. For Uri.EscapeDataString to work, iriParsing must be enabled.
EDIT
For those who want to generate Slugs URLs in C #, I recommend checking out this related question:
How does qaru generate urls optimized for SEO?
This is what I used for my project.
dana Nov 12 '13 at 18:30 2013-11-12 18:30
source share