deebug

SEO slug

Jan 29th, 2012
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.43 KB | None | 0 0
  1. public static string Slug(string s)
  2. {
  3.      s = s.Normalize(NormalizationForm.FormD);
  4.      StringBuilder sb = new StringBuilder();
  5.      foreach (char c in s) {
  6.         if (CharUnicodeInfo.GetUnicodeCategory(c) != UnicodeCategory.NonSpacingMark){
  7.             sb.Append(c);
  8.         }
  9.     }
  10.      s = sb.ToString().Normalize(NormalizationForm.FormC);
  11.      s = Regex.Replace(s, "[^a-z0-9_\-]+", "-", RegexOptions.IgnoreCase);
  12.      s = s.Trim(new char[] { "-" });
  13.      return s;
  14. }
Advertisement
Add Comment
Please, Sign In to add comment