Skip to content

Instantly share code, notes, and snippets.

@coreyjs
Created December 19, 2013 03:47
Show Gist options
  • Save coreyjs/8034124 to your computer and use it in GitHub Desktop.
Save coreyjs/8034124 to your computer and use it in GitHub Desktop.
c# string collection methods, early work
public static class StringExtensions
{
public static string Truncate(this string value, int maxLength) {
if (!string.IsNullOrEmpty(value) && value.Length > maxLength) {
return value.Substring(0, maxLength);
}
return value;
}
public static string SeoCleanString(this string input)
{
if (!string.IsNullOrEmpty(input))
{
input = input.Replace(' ', '-');
return Regex.Replace(input, @"[^A-Za-z0-9\-\s]", "");
}
return "";
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment