public static string EncodePageTitle(string title)
{
if (string.IsNullOrEmpty(title))
return title;
// Search engine friendly slug routine with help from http://www.intrepidstudios.com/blog/2009/2/10/function-to-generate-a-url-friendly-string.aspx
// remove invalid characters
title = Regex.Replace(title, @"[^\w\d\s-]", ""); // this is unicode safe, but may need to revert back to 'a-zA-Z0-9', need to check spec
// convert multiple spaces/hyphens into one space
title = Regex.Replace(title, @"[\s-]+", " ").Trim();
// If it's over 30 chars, take the first 30.
title = title.Substring(0, title.Length <= 75 ? title.Length : 75).Trim();
// hyphenate spaces
title = Regex.Replace(title, @"\s", "-");
return title;
}