Well, removing diacritics has been answered before.
public static string RemoveDiacritics(string text)
{
var normalizedString = text.Normalize(NormalizationForm.FormD);
var stringBuilder = new StringBuilder();
foreach (var c in normalizedString)
{
var unicodeCategory = CharUnicodeInfo.GetUnicodeCategory(c);
if (unicodeCategory != UnicodeCategory.NonSpacingMark)
{
stringBuilder.Append(c);
}
}
return stringBuilder.ToString().Normalize(NormalizationForm.FormC);
}
If you take RemoveDiacritics
, then all you need to do is some Regex replace, replacing all non-alpha numeric characters with a single dash.
public static string PrettyUrl(string s)
{
return Regex.Replace(RemoveDiacritics(s), "[^a-zA-Z0-9]+", "-").Trim('-');
}
Fiddle