Created
August 24, 2012 20:26
-
-
Save curtismitchell/3455258 to your computer and use it in GitHub Desktop.
Turns a string into a url-friendly slug
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// <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