BaseExtensions.cs 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. using System;
  2. using System.Security.Cryptography;
  3. using System.Text;
  4. using System.Text.RegularExpressions;
  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><see cref="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 Md5.
  25. /// </summary>
  26. /// <param name="str">The string.</param>
  27. /// <returns><see cref="Guid" />.</returns>
  28. public static Guid GetMD5(this string str)
  29. {
  30. #pragma warning disable CA5351
  31. using (var provider = MD5.Create())
  32. {
  33. return new Guid(provider.ComputeHash(Encoding.Unicode.GetBytes(str)));
  34. }
  35. #pragma warning restore CA5351
  36. }
  37. }
  38. }