BaseExtensions.cs 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637
  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 partial class BaseExtensions
  11. {
  12. // http://stackoverflow.com/questions/1349023/how-can-i-strip-html-from-text-in-net
  13. [GeneratedRegex(@"<(.|\n)*?>")]
  14. private static partial Regex StripHtmlRegex();
  15. /// <summary>
  16. /// Strips the HTML.
  17. /// </summary>
  18. /// <param name="htmlString">The HTML string.</param>
  19. /// <returns><see cref="string" />.</returns>
  20. public static string StripHtml(this string htmlString)
  21. => StripHtmlRegex().Replace(htmlString, string.Empty).Trim();
  22. /// <summary>
  23. /// Gets the Md5.
  24. /// </summary>
  25. /// <param name="str">The string.</param>
  26. /// <returns><see cref="Guid" />.</returns>
  27. public static Guid GetMD5(this string str)
  28. {
  29. #pragma warning disable CA5351
  30. return new Guid(MD5.HashData(Encoding.Unicode.GetBytes(str)));
  31. #pragma warning restore CA5351
  32. }
  33. }
  34. }