1
public
static
string
StripHtmlXmlTags(
string
content)
2
{
3
return Regex.Replace(content, "<[^>]+>", "", RegexOptions.IgnoreCase | RegexOptions.Compiled);
4
}
5
6
去除html标签
#region 去除html标签
7
8
// Strip All Tags from a String
9
/**//*
10
* Takes a string and strips all bbcode and html from the
11
* the string. Replacing any <br />s with linebreaks. This
12
* method is meant to be used by ToolTips to present a
13
* a stripped-down version of the post.Body
14
*
15
*/
16
/**//// <summary>
17
/// 去除所有html标签
18
/// </summary>
19
/// <param name="stringToStrip"></param>
20
/// <returns></returns>
21
public static string StripAllTags(string stringToStrip)
22
{
23
// paring using RegEx
24
//
25
stringToStrip = Regex.Replace(stringToStrip, "</p(?:\\s*)>(?:\\s*)<p(?:\\s*)>", "\n\n", RegexOptions.IgnoreCase | RegexOptions.Compiled);
26
stringToStrip = Regex.Replace(stringToStrip, "<br(?:\\s*)/>", "\n", RegexOptions.IgnoreCase | RegexOptions.Compiled);
27
stringToStrip = Regex.Replace(stringToStrip, "\"", "''", RegexOptions.IgnoreCase | RegexOptions.Compiled);
28
stringToStrip = StripHtmlXmlTags(stringToStrip);
29
return stringToStrip;
30
}
public
static
string
StripHtmlXmlTags(
string
content)2

{3
return Regex.Replace(content, "<[^>]+>", "", RegexOptions.IgnoreCase | RegexOptions.Compiled);4
}
5

6

去除html标签
#region 去除html标签7

8
// Strip All Tags from a String9

/**//*10
* Takes a string and strips all bbcode and html from the11
* the string. Replacing any <br />s with linebreaks. This12
* method is meant to be used by ToolTips to present a13
* a stripped-down version of the post.Body14
*15
*/16

/**//// <summary>17
/// 去除所有html标签18
/// </summary>19
/// <param name="stringToStrip"></param>20
/// <returns></returns>21
public static string StripAllTags(string stringToStrip)22

{23
// paring using RegEx24
//25
stringToStrip = Regex.Replace(stringToStrip, "</p(?:\\s*)>(?:\\s*)<p(?:\\s*)>", "\n\n", RegexOptions.IgnoreCase | RegexOptions.Compiled);26
stringToStrip = Regex.Replace(stringToStrip, "<br(?:\\s*)/>", "\n", RegexOptions.IgnoreCase | RegexOptions.Compiled);27
stringToStrip = Regex.Replace(stringToStrip, "\"", "''", RegexOptions.IgnoreCase | RegexOptions.Compiled);28
stringToStrip = StripHtmlXmlTags(stringToStrip);29
return stringToStrip;30
}

被折叠的 条评论
为什么被折叠?



