jellyfin/MediaBrowser.Common/Extensions/BaseExtensions.cs

45 lines
1.2 KiB
C#
Raw Normal View History

2020-04-19 13:18:28 +00:00
#nullable enable
using System;
2019-12-10 23:13:57 +00:00
using System.Security.Cryptography;
using System.Text;
2018-12-27 23:27:57 +00:00
using System.Text.RegularExpressions;
namespace MediaBrowser.Common.Extensions
{
/// <summary>
2019-12-10 23:13:57 +00:00
/// Class BaseExtensions.
2018-12-27 23:27:57 +00:00
/// </summary>
public static class BaseExtensions
{
/// <summary>
/// Strips the HTML.
/// </summary>
/// <param name="htmlString">The HTML string.</param>
2019-09-20 10:42:08 +00:00
/// <returns><see cref="string" />.</returns>
2018-12-27 23:27:57 +00:00
public static string StripHtml(this string htmlString)
{
// http://stackoverflow.com/questions/1349023/how-can-i-strip-html-from-text-in-net
2019-09-20 10:42:08 +00:00
const string Pattern = @"<(.|\n)*?>";
2018-12-27 23:27:57 +00:00
2019-09-20 10:42:08 +00:00
return Regex.Replace(htmlString, Pattern, string.Empty).Trim();
2018-12-27 23:27:57 +00:00
}
/// <summary>
2019-09-20 10:42:08 +00:00
/// Gets the Md5.
2018-12-27 23:27:57 +00:00
/// </summary>
2019-09-20 10:42:08 +00:00
/// <param name="str">The string.</param>
/// <returns><see cref="Guid" />.</returns>
2018-12-27 23:27:57 +00:00
public static Guid GetMD5(this string str)
{
2019-12-10 23:13:57 +00:00
#pragma warning disable CA5351
using (var provider = MD5.Create())
{
return new Guid(provider.ComputeHash(Encoding.Unicode.GetBytes(str)));
}
2019-12-10 23:13:57 +00:00
#pragma warning restore CA5351
2018-12-27 23:27:57 +00:00
}
}
}