Share Pastebin
Guest
Public paste!

Untitled

By: a guest | Aug 11th, 2009 | Syntax: C# | Size: 1.00 KB | Hits: 167 | Expires: Never
Copy text to clipboard
  1.  /// <summary>
  2.         /// clear text to put in url
  3.         /// </summary>
  4.         public string ClearString(string title)
  5.         {
  6.             // Substitute spaces          
  7.             // Remove illegal characters    
  8.             string normalizedString = title.Normalize(NormalizationForm.FormD);
  9.             StringBuilder sb = new StringBuilder();
  10.             for (int i = 0; i < normalizedString.Length; i++)
  11.             {
  12.                 UnicodeCategory uc = CharUnicodeInfo.GetUnicodeCategory(normalizedString[i]);
  13.                 if (uc != UnicodeCategory.NonSpacingMark)
  14.                 {
  15.                     sb.Append(normalizedString[i]);
  16.                 }
  17.             }
  18.             return sb.ToString().Normalize(NormalizationForm.FormD).Trim().Replace("-", "").Replace(",", "").Replace(" ", "-").Replace(".", "-").Replace("¿", "").Replace("?", "").Replace("!", "").Replace("¡", "").Replace("--", "-").Replace(Convert.ToChar(34).ToString(), "").Replace(":","-").Replace("%","") + "/";
  19.          }