Skip to content

Instantly share code, notes, and snippets.

@curtismitchell
Created August 24, 2012 20:26
Show Gist options
  • Save curtismitchell/3455258 to your computer and use it in GitHub Desktop.
Save curtismitchell/3455258 to your computer and use it in GitHub Desktop.
Turns a string into a url-friendly slug
/// <summary>
/// Represents a string as a url-friendly string
/// </summary>
static class SlugExtension
{
static public string ToSlug(this string unslugged)
{
var result = new Regex(@"[~`!@#\$%\^&\*\(\)_\+=\.><,\[\]{}]").Replace(unslugged, "");
result = new Regex(@"[\s]+").Replace(result, "-");
return result.ToLower();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment