如何在asp.net中创建内容管理 [英] How to create content Managment In asp.net
本文介绍了如何在asp.net中创建内容管理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在用ASP创建内容管理.在sql数据库中,该表包含HTML标记和网站内容数据存储的表.我想从sql表查看网站内容到asp的文本框,但我不想在asp的文本框中查看HTML标记.请帮助我,我是.net的新手
感谢和问候
I m creating content management in asp .In sql database contains table in that HTML tag and website content data is stored. I want to view website content from sql table to text box of asp but i don''t want to view HTML tag in text box of asp. please help me i m new in .net
Thanks and regards
推荐答案
using System;
using System.Text.RegularExpressions;
/// <summary>
/// Methods to remove HTML from strings.
/// </summary>
public static class HtmlRemoval
{
/// <summary>
/// Remove HTML from string with Regex.
/// </summary>
public static string StripTagsRegex(string source)
{
return Regex.Replace(source, "<.*?>", string.Empty);
}
/// <summary>
/// Compiled regular expression for performance.
/// </summary>
static Regex _htmlRegex = new Regex("<.*?>", RegexOptions.Compiled);
/// <summary>
/// Remove HTML from string with compiled Regex.
/// </summary>
public static string StripTagsRegexCompiled(string source)
{
return _htmlRegex.Replace(source, string.Empty);
}
/// <summary>
/// Remove HTML tags from string using char array.
/// </summary>
public static string StripTagsCharArray(string source)
{
char[] array = new char[source.Length];
int arrayIndex = 0;
bool inside = false;
for (int i = 0; i < source.Length; i++)
{
char let = source[i];
if (let == ''<'')
{
inside = true;
continue;
}
if (let == ''>'')
{
inside = false;
continue;
}
if (!inside)
{
array[arrayIndex] = let;
arrayIndex++;
}
}
return new string(array, 0, arrayIndex);
}
}
using System;
using System.Text.RegularExpressions;
class Program
{
static void Main()
{
const string html = "<p>There was a .NET programmer " +
"and he stripped the HTML tags.</p>";
Console.WriteLine(HtmlRemoval.StripTagsRegex(html));
Console.WriteLine(HtmlRemoval.StripTagsRegexCompiled(html));
Console.WriteLine(HtmlRemoval.StripTagsCharArray(html));
}
}
这给出了
This gives
<p>There was a <b>.NET</b> programmer " +
"and he stripped the <i>HTML</i> tags.</p>
有一个.NET程序员,他剥离了HTML标记.
There was a .NET programmer and he stripped the HTML tags.
这篇关于如何在asp.net中创建内容管理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文