BaseExtensions.cs 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. using System;
  2. using System.Text;
  3. using System.Text.RegularExpressions;
  4. using System.Security.Cryptography;
  5. namespace MediaBrowser.Common.Extensions
  6. {
  7. /// <summary>
  8. /// Class BaseExtensions
  9. /// </summary>
  10. public static class BaseExtensions
  11. {
  12. /// <summary>
  13. /// Strips the HTML.
  14. /// </summary>
  15. /// <param name="htmlString">The HTML string.</param>
  16. /// <returns>System.String.</returns>
  17. public static string StripHtml(this string htmlString)
  18. {
  19. // http://stackoverflow.com/questions/1349023/how-can-i-strip-html-from-text-in-net
  20. const string pattern = @"<(.|\n)*?>";
  21. return Regex.Replace(htmlString, pattern, string.Empty).Trim();
  22. }
  23. /// <summary>
  24. /// Gets the M d5.
  25. /// </summary>
  26. /// <param name="str">The STR.</param>
  27. /// <returns>Guid.</returns>
  28. public static Guid GetMD5(this string str)
  29. {
  30. using (var provider = MD5.Create())
  31. {
  32. return new Guid(provider.ComputeHash(Encoding.Unicode.GetBytes(str)));
  33. }
  34. }
  35. }
  36. }