2
0

BaseExtensions.cs 1.2 KB

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