UBB(c#完整版)

ubb

最近我又开始用c#做论坛,在网上找了一下,虽然也有关于ubb(c#)的转换代码,可是同样都不全面,我在这里补充了一下,拿出来和大家共享。
有什么问题到我个人的论坛www.hushiyu.com来交流,随时欢迎。

using System;
using System.Text;
using System.Text.RegularExpressions;

namespace myluntan
{
 /// <summary>
 /// UBB 的摘要说明。
 /// </summary>
 public class UBB
 {
  public UBB()
  {
   //
   // TODO: 在此处添加构造函数逻辑
   //
  }
   
  #region 公共静态方法
  /// <summary>
  /// UBB代码处理函数
  /// </summary>
  /// <param name="sDetail">输入字符串</param>
  /// <returns>输出字符串</returns>
  public string UBBToHTML(string sDetail)
  {
   Regex r;
   Match m;
   #region 处理空格
   sDetail = sDetail.Replace(" "," ");
   #endregion
   #region 处理单引号
   sDetail = sDetail.Replace("'","’");
   #endregion
   #region 处理双引号
   sDetail = sDetail.Replace("\"",""");
   #endregion
   #region html标记符
   sDetail = sDetail.Replace("<","<");
   sDetail = sDetail.Replace(">",">");
   
   #endregion
   #region 处理换行
   //处理换行,在每个新行的前面添加两个全角空格
   r = new Regex(@"(\r\n(( )| )+)(?<正文> +)",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
   #region 处标记
   r = new Regex(@"(\[b\])([ \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 处标记
   r = new Regex(@"(\[i\])([ \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 处标记
   r = new Regex(@"(\[U\])([ \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\])([ \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\])([ \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 处标记
   //处标记
   r = new Regex(@"(\[url\])([ \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\">" +
     m.Groups[2].ToString() + "</A>");
   }
   #endregion
   #region 处标记
   //处标记
   r = new Regex(@"(\[url=([ \t]+)\])([ \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\">" +
     m.Groups[3].ToString() + "</A>");
   }
   #endregion
   #region 处标记
   //处标记
   r = new Regex(@"(\[email\])([ \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\">" +
     m.Groups[2].ToString() + "</A>");
   }
   #endregion
   #region 处标记
   //处标记
   r = new Regex(@"(\[email=([ \t]+)\])([ \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\">" +
     m.Groups[3].ToString() + "</A>");
   }
   #endregion
   #region 处标记
   //处标记
   r = new Regex(@"(\[size=([1-7])\])([ \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 处标记
   //处标记
   r = new Regex(@"(\[color=([ ]+)\])([ \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=([ ]+)\])([ \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=([ ]+)\])([ \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])\])([ \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 处理

   //处理

   r = new Regex(@"(\[list(=(A|a|I|i| ))?\]([ \t]*)\r\n)((\[\*\]([ \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(@"\[\*\]([ \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 处[SHADOW=x][/shadow]标记
   //处[SHADOW=x][/shadow]标记
   r = new Regex(@"(\[SHADOW=)(\d*?),(#*\w*?),(\d*?)\]([ \t]*?)(\[\/SHADOW\])",RegexOptions.IgnoreCase);
   for (m = r.Match(sDetail); m.Success; m = m.NextMatch())
   {
    sDetail = sDetail.Replace(m.Groups[0].ToString(),
     "<TABLE WIDTH=" + m.Groups[2].ToString() + "  STYLE=FILTER:SHADOW(COLOR=" + m.Groups[3].ToString() + ", STRENGTH=" + m.Groups[4].ToString() + ")>" +
     m.Groups[5].ToString() + "</TABLE>");
   }
   #endregion
   #region 处[glow=x][/glow]标记
   //处[glow=x][/glow]标记
   r = new Regex(@"(\[glow=)(\d*?),(#*\w*?),(\d*?)\]([ \t]*?)(\[\/glow\])",RegexOptions.IgnoreCase);
   for (m = r.Match(sDetail); m.Success; m = m.NextMatch())
   {
    sDetail = sDetail.Replace(m.Groups[0].ToString(),
     "<TABLE WIDTH=" + m.Groups[2].ToString() + "  STYLE=FILTER:GLOW(COLOR=" + m.Groups[3].ToString() + ", STRENGTH=" + m.Groups[4].ToString() + ")>" +
     m.Groups[5].ToString() + "</TABLE>");
   }
   #endregion
   #region 处标记
   r = new Regex(@"(\[center\])([ \t]*?)(\[\/center\])",RegexOptions.IgnoreCase);
   for (m = r.Match(sDetail); m.Success; m = m.NextMatch())
   {
    sDetail = sDetail.Replace(m.Groups[0].ToString(),"<CENTER>" + m.Groups[2].ToString() + "</CENTER>");
   }
   #endregion
   #region 处[IMG][/IMG]标记
   r = new Regex(@"(\[IMG\])(http|https|ftp):\/\/([ \t]*?)(\[\/IMG\])",RegexOptions.IgnoreCase);
   for (m = r.Match(sDetail); m.Success; m = m.NextMatch())
   {
    sDetail = sDetail.Replace(m.Groups[0].ToString(),"<br><a onfocus=this.blur() href=" + m.Groups[2].ToString() + "://" + m.Groups[3].ToString() + " target=_blank><IMG SRC=" + m.Groups[2].ToString() + "://" + m.Groups[3].ToString() + " border=0 alt=按此在新窗口浏览图片 onload=javascript:if(screen.width-333<this.width)this.width=screen.width-333></a>");
   }
   #endregion
   #region 处[em]标记
   r = new Regex(@"(\[em([ \t]*?)\])",RegexOptions.IgnoreCase);
   for (m = r.Match(sDetail); m.Success; m = m.NextMatch())
   {
    sDetail = sDetail.Replace(m.Groups[0].ToString(),"<img src=pic/em" + m.Groups[2].ToString() + ".gif border=0 align=middle>");
   }
   #endregion
   #region 处[flash=x][/flash]标记
   //处[mp=x][/mp]标记
   r = new Regex(@"(\[flash=)(\d*?),(\d*?)\]([ \t]*?)(\[\/flash\])",RegexOptions.IgnoreCase);
   for (m = r.Match(sDetail); m.Success; m = m.NextMatch())
   {
    sDetail = sDetail.Replace(m.Groups[0].ToString(),
     "<a href=" + m.Groups[4].ToString() + " TARGET=_blank><IMG SRC=http://www.163design.net/n/c/pic/swf.gif border=0 alt=点击开新窗口欣赏该FLASH动画!> [全屏欣赏]</a><br><br><OBJECT codeBase=http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0 classid=clsid:D27CDB6E-AE6D-11cf-96B8-444553540000 width=" + m.Groups[2].ToString() + " height=" + m.Groups[3].ToString() + "><PARAM NAME=movie VALUE=" + m.Groups[4].ToString() + "><PARAM NAME=quality VALUE=high><param name=menu value=false><embed src=" + m.Groups[4].ToString() + " quality=high menu=false pluginspage=http://www.macromedia.com/go/getflashplayer type=application/x-shockwave-flash width=" + m.Groups[2].ToString() + " height=" + m.Groups[3].ToString() + ">" + m.Groups[4].ToString() + "</embed></OBJECT>");
   }
   #endregion
   #region 处[dir=x][/dir]标记
   //处[dir=x][/dir]标记
   r = new Regex(@"(\[dir=)(\d*?),(\d*?)\]([ \t]*?)(\[\/dir\])",RegexOptions.IgnoreCase);
   for (m = r.Match(sDetail); m.Success; m = m.NextMatch())
   {
    sDetail = sDetail.Replace(m.Groups[0].ToString(),
     "<object classid=clsid:166B1BCA-3F9C-11CF-8075-444553540000 codebase=http://download.macromedia.com/pub/shockwave/cabs/director/sw.cab#version=7,0,2,0 width=" + m.Groups[2].ToString() + " height=" + m.Groups[3].ToString() + "><param name=src value=" + m.Groups[4].ToString() + "><embed src=" + m.Groups[4].ToString() + " pluginspage=http://www.macromedia.com/shockwave/download/ width=" + m.Groups[2].ToString() + " height=" + m.Groups[3].ToString() + "></embed></object>");
   }
   #endregion
   #region 处[rm=x][/rm]标记
   //处[rm=x][/rm]标记
   r = new Regex(@"(\[rm=)(\d*?),(\d*?)\]([ \t]*?)(\[\/rm\])",RegexOptions.IgnoreCase);
   for (m = r.Match(sDetail); m.Success; m = m.NextMatch())
   {
    sDetail = sDetail.Replace(m.Groups[0].ToString(),
     "<OBJECT classid=clsid:CFCDAA03-8BE4-11cf-B84B-0020AFBBCCFA class=OBJECT id=RAOCX width=" + m.Groups[2].ToString() + " height=" + m.Groups[3].ToString() + "><PARAM NAME=SRC VALUE=" + m.Groups[4].ToString() + "><PARAM NAME=CONSOLE VALUE=Clip1><PARAM NAME=CONTROLS VALUE=imagewindow><PARAM NAME=AUTOSTART VALUE=true></OBJECT><br><OBJECT classid=CLSID:CFCDAA03-8BE4-11CF-B84B-0020AFBBCCFA height=32 id=video2 width=" + m.Groups[2].ToString() + "><PARAM NAME=SRC VALUE=" + m.Groups[4].ToString() + "><PARAM NAME=AUTOSTART VALUE=-1><PARAM NAME=CONTROLS VALUE=controlpanel><PARAM NAME=CONSOLE VALUE=Clip1></OBJECT>");
   }
   #endregion
   #region 处[mp=x][/mp]标记
   //处[mp=x][/mp]标记
   r = new Regex(@"(\[mp=)(\d*?),(\d*?)\]([ \t]*?)(\[\/mp\])",RegexOptions.IgnoreCase);
   for (m = r.Match(sDetail); m.Success; m = m.NextMatch())
   {
    sDetail = sDetail.Replace(m.Groups[0].ToString(),
     "<object align=middle classid=CLSID:22d6f312-b0f6-11d0-94ab-0080c74c7e95 class=OBJECT id=MediaPlayer width=" + m.Groups[2].ToString() + " height=" + m.Groups[3].ToString() + " ><param name=ShowStatusBar value=-1><param name=Filename value=" + m.Groups[4].ToString() + "><embed type=application/x-oleobject codebase=http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=5,1,52,701 flename=mp src=" + m.Groups[4].ToString() + "  width=" + m.Groups[2].ToString() + " height=" + m.Groups[3].ToString() + "></embed></object>");
   }
   #endregion
   #region 处[qt=x][/qt]标记
   //处[qt=x][/qt]标记
   r = new Regex(@"(\[qt=)(\d*?),(\d*?)\]([ \t]*?)(\[\/qt\])",RegexOptions.IgnoreCase);
   for (m = r.Match(sDetail); m.Success; m = m.NextMatch())
   {
    sDetail = sDetail.Replace(m.Groups[0].ToString(),
     "<embed src=" + m.Groups[4].ToString() + " width=" + m.Groups[2].ToString() + " height=" + m.Groups[3].ToString() + " autoplay=true loop=false controller=true playeveryframe=false cache=false scale=TOFIT bgcolor=#000000 kioskmode=false targetcache=false pluginspage=http://www.apple.com/quicktime/>");
   }
   #endregion
   #region 处标记
   r = new Regex(@"(\[QUOTE\])([ \t]*?)(\[\/QUOTE\])",RegexOptions.IgnoreCase);
   for (m = r.Match(sDetail); m.Success; m = m.NextMatch())
   {
    sDetail = sDetail.Replace(m.Groups[0].ToString(),"<table cellpadding=0 cellspacing=0 border=1 WIDTH=94% bordercolor=#000000 bgcolor=#F2F8FF align=center  style=FONT-SIZE: 9pt><tr><td  ><table width=100% cellpadding=5 cellspacing=1 border=0><TR><TD >" + m.Groups[2].ToString() + "</table></table><br>");
   }
   #endregion
   #region 处标记
   r = new Regex(@"(\[move\])([ \t]*?)(\[\/move\])",RegexOptions.IgnoreCase);
   for (m = r.Match(sDetail); m.Success; m = m.NextMatch())
   {
    sDetail = sDetail.Replace(m.Groups[0].ToString(),"<MARQUEE scrollamount=3>" + m.Groups[2].ToString() + "</MARQUEE>");
   }
   #endregion
   #region 处标记
   r = new Regex(@"(\[FLY\])([ \t]*?)(\[\/FLY\])",RegexOptions.IgnoreCase);
   for (m = r.Match(sDetail); m.Success; m = m.NextMatch())
   {
    sDetail = sDetail.Replace(m.Groups[0].ToString(),"<MARQUEE width=80% behavior=alternate scrollamount=3>" + m.Groups[2].ToString() + "</MARQUEE>");
   }
   #endregion
   #region 处[image][/image]标记
   //处[image][/image]标记
   r = new Regex(@"(\[image\])([ \t]*?)(\[\/image\])",RegexOptions.IgnoreCase);
   for (m = r.Match(sDetail); m.Success; m = m.NextMatch())
   {
    sDetail = sDetail.Replace(m.Groups[0].ToString(),
     "<img src=\"" + m.Groups[2].ToString() + "\" border=0 align=middle><br>");
   }
   #endregion

   return sDetail;
  }
  #endregion
 }
}

时间: 2024-12-09 08:57:36

UBB(c#完整版)的相关文章

求完整版的电脑版的商城平台---eclipse可以使用的

问题描述 求完整版的电脑版的商城平台---eclipse可以使用的 20C 直接复制到eclipse里就可以使用的商城平台,不需要太复杂的. 解决方案 http://download.csdn.net/download/surblue/3763533http://download.csdn.net/download/www478347671/5296633http://download.csdn.net/detail/f524089156/2962689 解决方案二: http://www.sh

js分页-java js完整版分页后台

问题描述 java js完整版分页后台 求完整版js分页代码,最好是从action中带参数的用hibernate分页 解决方案 用js插件........

Ajax创建XMLHttpRequest完整版

ajax|request|xml|xmlhttprequest|创建 以下就是创建XMLHttpRequest完整版的代码,希望对大家有用~ function createXMLHttpRequest(){   if(window.ActiveXObject)  {    try {                 xmlHttpRequest = new ActiveXObject("Msxml3.XMLHTTP");        } catch (e) {    try {   

MicrosoftVBscript运行时错误(完整版)共121个

vbscript|错误|vbscript MicrosoftVBscript运行时错误(完整版)共121个 MicrosoftVBscript运行时错误(0x000A0005) 无效的过程调用或参数 MicrosoftVBscript运行时错误(0x000A0005) 无效的过程调用或参数 MicrosoftVBscript运行时错误(0x000A0006) 溢出 MicrosoftVBscript运行时错误(0x000A0007) 内存不够 MicrosoftVBscript运行时错误(0x0

全球IP地址查询完整版

ip地址 全球IP地址查询完整版 突然在某某网站看到IP地址查询,于是心血来潮做了一个.这是用asp查询全球IP地址的程式,由于类似的的用Asp查询IP的速度不是很理想,本人使用的也是宏志宏的IP地址数据库,只是对它进行了改进. 本人在 win98+pws+access2000上测试通过,效果比较理想. 数据库的设计在一个软件中的比例,毫不夸张的说占60%,虽然这是一个小的程式,但也得到一定的体现. 有任何错误或建议请一定要给我发E-mail: ljz811@163.com  ,我也不了解"追捕

多文件上载系统完整版

<?php //多文件上载系统完整版 //功能强大,可任意控制上载文件数,是否覆盖 include("../include/common.inc"); $title = "多个文件的上载程序"; include("../include/header.inc"); //定义允许上载文件的数目 define("UPLOAD_NO", 10); echo("<p align='center'><fo

php多文件上载系统完整版

<?php //多文件上载系统完整版 include("../include/common.inc"); $title = "多个文件的上载程序"; include("../include/header.inc"); //定义允许上载文件的数目 define("UPLOAD_NO", 10); echo("<p align='center'><font size='4' color='#000

javascript贪吃蛇完整版

 这篇文章主要是对javascript贪吃蛇完整版(源码)进行了详细的分析介绍,需要的朋友可以过来参考下,希望对大家有所帮助 javascript贪吃蛇完整版 注释完整,面向对象 代码如下: <html> <head>     <title>贪吃蛇 Snake v2.4</title> <style>     body{         font-size:9pt;     }     table{         border-collapse

人人商城V3 3.1.3 完整版 微擎微赞通用模块优化修复V3版本

拿去卖钱就没意思啦,好东西大家一起分享 V3-3.1.3升级日志: 优化 后台链接选择器 支持选择全民股东 修复 多商户 商家入驻短信通知问题 优化 创建订单 设置自定表单后仍然显示买家留言输入框 优化 兑换中心选择按钮显示的醒目度 优化 兑换中心导出兑换码命名,现在二维码图片按照兑换编号命名 修复 兑换中心组合兑换的优惠券总是按照随机模式发放的问题 修复 订单详情商品价格显示问题 修复 V3未开启新地址库 选择地址样式错位问题 修复 全返多规格无法添加小数问题 修复 商品详情地址过长位置错落问