I've been using this class for a while now to cleans data into such a form that I can use it in my URL's and I was wondering if there's a faster/better way?
The order of the replacements is important as it ensures that theres no slashes at the beginning on completion and theres no double slashes in side of the text.
/// <summary>
/// Cleanses String for URL
/// </summary>
/// <param name="s">string</param>
/// <returns>URL Friendly String</returns>
public static string Clean(this string s)
{
var sb = new StringBuilder(s.Trim());
sb.Replace("’", "");
sb.Replace("-", " ");
sb.Replace("/", "");
sb.Replace("&", "and");
sb.Replace(",", "");
sb.Replace(" ", " ");
sb.Replace(" ", "-");
sb.Replace("'", "");
sb.Replace(".", "");
sb.Replace("eacute;", "e");
sb.Replace("--", "-");
if (sb[0].ToString() == "-") { sb[0].ToString().Replace("-", ""); }
return sb.ToString().ToLower();
}
Thanks.