I'm looking at the MSFT Patterns开发者_高级运维 and Practices guide for MVC on Azure and they have code similar to the following:
public static string GenerateSlug(this string txt, int maxLength)
{
string str = RemoveAccent(txt).ToLower();
str = Regex.Replace(str, @"[^a-z0-9\s-]", string.Empty);
str = Regex.Replace(str, @"\s+", " ").Trim();
str = str.Substring(0, str.Length <= maxLength ? str.Length : maxLength).Trim();
str = Regex.Replace(str, @"\s", "-");
return str;
}
public static string RemoveAccent(this string txt)
{
byte[] bytes = System.Text.Encoding.GetEncoding("Cyrillic").GetBytes(txt);
return System.Text.Encoding.ASCII.GetString(bytes);
}
What changes will I have to make to support Eastern and non-english languages, and still keep the SEO benefit of the slug?
You may take a look at how the slugs are generated on StackOverflow.
精彩评论