In some cases, we need to get part of a block of HTML contents, if truncate it directly, the HTML tags will be truncated, too.
So before truncating, we have to remove all the HTML tags in the content.
The following JavaScript codes is used to remove HTML tags from a block of HTML codes:
function RemoveHTML( strText )
{
var regEx = /<[^>]*>/g;
return strText.replace(regEx, "");
}
the following is the C# codes to remove HTML tags:
private string RemoveHTMLInServer(string in_HTML)
{
return Regex.Replace(in_HTML, "<(.|\n)*?>", "");
}
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】博客园携手 AI 驱动开发工具商 Chat2DB 推出联合终身会员
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步