asp.net ubb使用代码

代码如下:

////别人写的ubb代码

using System;
using System.Text;
using System.Text.RegularExpressions;
namespace Test.Com
{
/// <summary>
/// 功能:UBB代码
/// 作者:Rexsp
/// 日期:2004-4-6
/// </summary>
public class UBB
{
#region 构造函数
public UBB()
{
//
// TODO: 在此处添加构造函数逻辑
//
}
#endregion
#region 公共静态方法
/// <summary>
/// UBB代码处理函数
/// </summary>
/// <param name="sDetail">输入字符串</param>
/// <returns>输出字符串</returns>
public static string UBBToHTML(string sDetail)
{
Regex r;
Match m;
#region 处理空格
sDetail = sDetail.Replace(" "," ");
#endregion
#region html标记符
sDetail = sDetail.Replace("<","<");
sDetail = sDetail.Replace(">",">");
#endregion
#region 处[b][/b]标记
r = new Regex(@"(\[b\])([ \S\t]*?)(\[\/b\])",RegexOptions.IgnoreCase);
for (m = r.Match(sDetail); m.Success; m = m.NextMatch())
{
sDetail = sDetail.Replace(m.Groups[0].ToString(),"<B>" + m.Groups[2].ToString() + "</B>");
}
#endregion
#region 处[i][/i]标记
r = new Regex(@"(\[i\])([ \S\t]*?)(\[\/i\])",RegexOptions.IgnoreCase);
for (m = r.Match(sDetail); m.Success; m = m.NextMatch())
{
sDetail = sDetail.Replace(m.Groups[0].ToString(),"<I>" + m.Groups[2].ToString() + "</I>");
}
#endregion
#region 处[u][/u]标记
r = new Regex(@"(\[U\])([ \S\t]*?)(\[\/U\])",RegexOptions.IgnoreCase);
for (m = r.Match(sDetail); m.Success; m = m.NextMatch())
{
sDetail = sDetail.Replace(m.Groups[0].ToString(),"<U>" + m.Groups[2].ToString() + "</U>");
}
#endregion
#region 处[p][/p]标记
//处[p][/p]标记
r = new Regex(@"((\r\n)*\[p\])(.*?)((\r\n)*\[\/p\])",RegexOptions.IgnoreCase|RegexOptions.Singleline);
for (m = r.Match(sDetail); m.Success; m = m.NextMatch())
{
sDetail = sDetail.Replace(m.Groups[0].ToString(),"<P class=\"pstyle\">" + m.Groups[3].ToString() + "</P>");
}
#endregion
#region 处[sup][/sup]标记
//处[sup][/sup]标记
r = new Regex(@"(\[sup\])([ \S\t]*?)(\[\/sup\])",RegexOptions.IgnoreCase);
for (m = r.Match(sDetail); m.Success; m = m.NextMatch())
{
sDetail = sDetail.Replace(m.Groups[0].ToString(),"<SUP>" + m.Groups[2].ToString() + "</SUP>");
}
#endregion
#region 处[sub][/sub]标记
//处[sub][/sub]标记
r = new Regex(@"(\[sub\])([ \S\t]*?)(\[\/sub\])",RegexOptions.IgnoreCase);
for (m = r.Match(sDetail); m.Success; m = m.NextMatch())
{
sDetail = sDetail.Replace(m.Groups[0].ToString(),"<SUB>" + m.Groups[2].ToString() + "</SUB>");
}
#endregion
#region 处[url][/url]标记
//处[url][/url]标记
r = new Regex(@"(\[url\])([ \S\t]*?)(\[\/url\])",RegexOptions.IgnoreCase);
for (m = r.Match(sDetail); m.Success; m = m.NextMatch())
{
sDetail = sDetail.Replace(m.Groups[0].ToString(),
"<A href=\"" + m.Groups[2].ToString() + "\" target=\"_blank\"><IMG border=0 src=\"images/url.gif\">" +
m.Groups[2].ToString() + "</A>");
}
#endregion
#region 处[url=xxx][/url]标记
//处[url=xxx][/url]标记
r = new Regex(@"(\[url=([ \S\t]+)\])([ \S\t]*?)(\[\/url\])",RegexOptions.IgnoreCase);
for (m = r.Match(sDetail); m.Success; m = m.NextMatch())
{
sDetail = sDetail.Replace(m.Groups[0].ToString(),
"<A href=\"" + m.Groups[2].ToString() + "\" target=\"_blank\"><IMG border=0 src=\"images/url.gif\">" +
m.Groups[3].ToString() + "</A>");
}
#endregion
#region 处[email][/email]标记
//处[email][/email]标记
r = new Regex(@"(\[email\])([ \S\t]*?)(\[\/email\])",RegexOptions.IgnoreCase);
for (m = r.Match(sDetail); m.Success; m = m.NextMatch())
{
sDetail = sDetail.Replace(m.Groups[0].ToString(),
"<A href=\"mailto:" + m.Groups[2].ToString() + "\" target=\"_blank\"><IMG border=0 src=\"images/email.gif\">" +
m.Groups[2].ToString() + "</A>");
}
#endregion
#region 处[email=xxx][/email]标记
//处[email=xxx][/email]标记
r = new Regex(@"(\[email=([ \S\t]+)\])([ \S\t]*?)(\[\/email\])",RegexOptions.IgnoreCase);
for (m = r.Match(sDetail); m.Success; m = m.NextMatch())
{
sDetail = sDetail.Replace(m.Groups[0].ToString(),
"<A href=\"mailto:" + m.Groups[2].ToString() + "\" target=\"_blank\"><IMG border=0 src=\"images/email.gif\">" +
m.Groups[3].ToString() + "</A>");
}
#endregion
#region 处[size=x][/size]标记
//处[size=x][/size]标记
r = new Regex(@"(\[size=([1-7])\])([ \S\t]*?)(\[\/size\])",RegexOptions.IgnoreCase);
for (m = r.Match(sDetail); m.Success; m = m.NextMatch())
{
sDetail = sDetail.Replace(m.Groups[0].ToString(),
"<FONT SIZE=" + m.Groups[2].ToString() + ">" +
m.Groups[3].ToString() + "</FONT>");
}
#endregion
#region 处[color=x][/color]标记
//处[color=x][/color]标记
r = new Regex(@"(\[color=([\S]+)\])([ \S\t]*?)(\[\/color\])",RegexOptions.IgnoreCase);
for (m = r.Match(sDetail); m.Success; m = m.NextMatch())
{
sDetail = sDetail.Replace(m.Groups[0].ToString(),
"<FONT COLOR=" + m.Groups[2].ToString() + ">" +
m.Groups[3].ToString() + "</FONT>");
}
#endregion
#region 处[font=x][/font]标记
//处[font=x][/font]标记
r = new Regex(@"(\[font=([\S]+)\])([ \S\t]*?)(\[\/font\])",RegexOptions.IgnoreCase);
for (m = r.Match(sDetail); m.Success; m = m.NextMatch())
{
sDetail = sDetail.Replace(m.Groups[0].ToString(),
"<FONT FACE=" + m.Groups[2].ToString() + ">" +
m.Groups[3].ToString() + "</FONT>");
}
#endregion
#region 处理图片链接
//处理图片链接
r = new Regex("\\[picture\\](\\d+?)\\[\\/picture\\]",RegexOptions.IgnoreCase);
for (m = r.Match(sDetail); m.Success; m = m.NextMatch())
{
sDetail = sDetail.Replace(m.Groups[0].ToString(),
"<A href=\"ShowImage.aspx?Type=ALL&Action=forumImage&ImageID=" + m.Groups[1].ToString() +
"\" target=\"_blank\"><IMG border=0 Title=\"点击打开新窗口查看\" src=\"ShowImage.aspx?Action=forumImage&ImageID=" + m.Groups[1].ToString() +
"\"></A>");
}
#endregion
#region 处理[align=x][/align]
//处理[align=x][/align]
r = new Regex(@"(\[align=([\S]+)\])([ \S\t]*?)(\[\/align\])",RegexOptions.IgnoreCase);
for (m = r.Match(sDetail); m.Success; m = m.NextMatch())
{
sDetail = sDetail.Replace(m.Groups[0].ToString(),
"<P align=" + m.Groups[2].ToString() + ">" +
m.Groups[3].ToString() + "</P>");
}
#endregion
#region 处[H=x][/H]标记
//处[H=x][/H]标记
r = new Regex(@"(\[H=([1-6])\])([ \S\t]*?)(\[\/H\])",RegexOptions.IgnoreCase);
for (m = r.Match(sDetail); m.Success; m = m.NextMatch())
{
sDetail = sDetail.Replace(m.Groups[0].ToString(),
"<H" + m.Groups[2].ToString() + ">" +
m.Groups[3].ToString() + "</H" + m.Groups[2].ToString() + ">");
}
#endregion
#region 处理[list=x][*][/list]
//处理[list=x][*][/list]
r = new Regex(@"(\[list(=(A|a|I|i| ))?\]([ \S\t]*)\r\n)((\[\*\]([ \S\t]*\r\n))*?)(\[\/list\])",RegexOptions.IgnoreCase);
for (m = r.Match(sDetail); m.Success; m = m.NextMatch())
{
string strLI = m.Groups[5].ToString();
Regex rLI = new Regex(@"\[\*\]([ \S\t]*\r\n?)",RegexOptions.IgnoreCase);
Match mLI;
for (mLI = rLI.Match(strLI); mLI.Success; mLI = mLI.NextMatch())
{
strLI = strLI.Replace(mLI.Groups[0].ToString(),"<LI>" + mLI.Groups[1]);
}
sDetail = sDetail.Replace(m.Groups[0].ToString(),
"<UL TYPE=\"" + m.Groups[3].ToString() + "\"><B>" + m.Groups[4].ToString() + "</B>" +
strLI + "</UL>");
}
#endregion
#region 处理换行
//处理换行,在每个新行的前面添加两个全角空格
r = new Regex(@"(\r\n(( )| )+)(?<正文>\S+)",RegexOptions.IgnoreCase);
for (m = r.Match(sDetail); m.Success; m = m.NextMatch())
{
sDetail = sDetail.Replace(m.Groups[0].ToString(),"<BR>  " + m.Groups["正文"].ToString());
}
//处理换行,在每个新行的前面添加两个全角空格
sDetail = sDetail.Replace("\r\n","<BR>");
#endregion
return sDetail;
}
#endregion
}
}

asp.net(c#) ubb处理类
http://www.jb51.net/article/15615.htm

(0)

相关推荐

  • asp.net ubb使用代码

    复制代码 代码如下: ////别人写的ubb代码 using System; using System.Text; using System.Text.RegularExpressions; namespace Test.Com { /// <summary> /// 功能:UBB代码 /// 作者:Rexsp /// 日期:2004-4-6 /// </summary> public class UBB { #region 构造函数 public UBB() { // // TO

  • asp下载防盗链代码

    asp下载防盗链代码第一种:  终于对下载系统做了个防盗链措施,在下载的页面头部做了如下代码,相关代码如下:   复制代码 代码如下: <%   From_url = Cstr(Request.ServerVariables("HTTP_REFERER"))   Serv_url = Cstr(Request.ServerVariables("SERVER_NAME"))   if mid(From_url,8,len(Serv_url)) <> 

  • ASP连接数据库的全能代码

    ASP连接数据库的全能代码      '解决了ACCESS数据库路径的问题! '采用DBType=0或DBType=1来区分AC库还是MSSQL库 '具体采用AC库时应注意的事项,请看程序说明 -------------------------------------------------------------------------------- Dim DBType,Conn,StrConn DBType=0        '0为Access数据库,1为MSSQL数据库 If(DBTyp

  • asp的ubb函数(推荐)

    复制代码 代码如下: function unHtml(content) unHtml=content if content <> "" then unHtml=replace(unHtml,"&","&") unHtml=replace(unHtml,"<","<") unHtml=replace(unHtml,">",">&

  • IIS ASP.NET 版本转换批处理代码

    标识符的查看方法:iisaspnet.bat代码 复制代码 代码如下: @echo off echo ########################################## echo ######### IIS ASP.NET 版本转换 ########## echo ########################################## echo 说明: echo 站点标识符:打开IIS 管理器后点击"网站"在每个站点名称后都有一个唯一的站点标识符 ech

  • 将HTML或txt文件转换为ASP输出的vbs代码

    使用方法:手工修改html文件的名称与想要生成的asp的文件名称,然后将下面的代码保存为1.vbs,跟1.html放同一个目录双击运行即可. 复制代码 代码如下: html = "1.html" asp = "1.asp" Set fso = CreateObject("Scripting.FileSystemObject") Set fhtml = fso.OpenTextFile(html, 1) Set fasp = fso.OpenTex

  • ASP.NET 高性能分页代码

    最近给分页快搞死,记得之前曾经发过修改DW ASP分页的方法,后来又写过手工打造的ASP分页,现在进入.NET当然要配合存储过程打造纯手工高性能分页了. 为什么会叫做高性能,为什么要手工打造,不使用.NET现有的分页控件呢?这个还要追溯到我修改DW ASP分页的时候,那个我还不怎么懂程序这个东西,只会修修补补,就更不要去谈什么性能问题.当时改的很心烦,接着叫我的私人技术总监张总帮我看看,当时张总就以一种不屑一顾的眼神往着我,说了句话:值得吗? 接着到我手工打造ASP分页,又搞不下去了,张总丢给我

  • asp.net 添加水印的代码(已测试)

    加水印的功能代码如下所示 复制代码 代码如下: /// <summary> /// 图片修改类,主要是用来保护图片版权的,版权归原作者所有 /// </summary> public class picmark { #region "member fields" private string modifyImagePath = null; private string drawedImagePath = null; private int rightSpace;

  • asp.net生成验证码代码(纯中文)

    复制代码 代码如下: using System; using System.Data; using System.Configuration; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls; usi

  • asp.net各种cookie代码和解析实例

    Cookie是一段文本信息,在客户端存储 Cookie 是 ASP.NET 的会话状态将请求与会话关联的方法之一.Cookie 也可以直接用于在请求之间保持数据,但数据随后将存储在客户端并随每个请求一起发送到服务器.浏览器对 Cookie 的大小有限制,因此,只有不超过 4096 字节才能保证被接受. 编写Cookie 复制代码 代码如下: //方式1:Response.Cookies["username"].value="mike";Response.Cookie

随机推荐