forked from anjoy8/Blog.Core
-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathHtmlHelper.cs
More file actions
28 lines (25 loc) · 845 Bytes
/
HtmlHelper.cs
File metadata and controls
28 lines (25 loc) · 845 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
using System;
using System.Collections.Generic;
using System.Text;
namespace Blog.Core.Common.Helper
{
public static class HtmlHelper
{
#region 去除富文本中的HTML标签
/// <summary>
/// 去除富文本中的HTML标签
/// </summary>
/// <param name="html"></param>
/// <param name="length"></param>
/// <returns></returns>
public static string ReplaceHtmlTag(string html, int length = 0)
{
string strText = System.Text.RegularExpressions.Regex.Replace(html, "<[^>]+>", "");
strText = System.Text.RegularExpressions.Regex.Replace(strText, "&[^;]+;", "");
if (length > 0 && strText.Length > length)
return strText.Substring(0, length);
return strText;
}
#endregion
}
}