UBB(C#)

  参考了一些文章,整理了一下,大家可以直接拿去用吧,其实自从有了FreeTextBox这样的东东出现,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 处标记
   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 处标记
   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 处标记
   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 处标记
   //处标记
   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 处标记
   //处标记
   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 处标记
   //处标记
   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 处标记
   //处标记
   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 处标记
   //处标记
   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 处标记
   //处标记
   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 处理

   //处理

   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 }
}

时间: 2024-08-03 08:20:03

UBB(C#)的相关文章

表情发布(类似QQ表情)和UBB类(c#)

ubb 最近由于项目的需要,特别做了个表情的发布(类似QQ表情)和UBB的类^_^ 大家看下图: 表情: UBB类的应用: 其实都很简单的,如果大家有兴趣的话可以给我发邮件,我会提供源代码. ps:由于没有空间,只能靠邮件了^_^

利用Jmail发送和接收邮件(C#)

jmail|收邮件 using System;using jmail;using System.Collections; namespace TYM.Com.MyMail{?/// ?/// 邮件发送接收类?/// ?public class Mail?{??/// ??/// 邮件类的构造函数??/// ??public Mail()??{??} ??/// ??/// 邮件模型??/// ??public MailModel model = new MailModel();??/// ??/

将控件中的数据输出保存到本地excel或word中,同时保存图片到本地(c#)

excel|word|控件|数据 //把table控件中的数据保存到excel或word public void Save(System.Web.UI.Control source, DocumentType type) { Response.Clear(); Response.Buffer= true; //设置Http的头信息,编码格式 if (type == DocumentType.Excel) { //Excel Response.AppendHeader("Content-Dispo

C#版的数据结构(对链表的操作)

我们一般只是学过C/C++的数据结构,想必学C#的学生会疑惑,为什么C#没有数据结构呢,那我来告诉你,其实C#也是有数据结构的,只不过我们不了解罢了,经过我半天的编程,终于把C#的数据结构写出来了,也大大增加了我对数据结构的理解,在这里提供出来,共享学习,共同进步!   using System;using System.Collections.Generic;using System.Linq;using System.Text; namespace 控制台程序{    class CShar

100分,,,,,,,,ASP.NET C# WEB (BS)开发,你们都是用什么 建模 的,用什么 工具 ????

问题描述 如题 解决方案 解决方案二:我用的是EA解决方案三:我用的是vs2005TS解决方案四:vs2008TS解决方案五:引用2楼loveskygirl521的回复: 我用的是vs2005TS 解决方案六:什么啊?我问用什么建模工具??不是VS版本解决方案七:rationalRose7不支持C#,本来还想用Rose来着,该死解决方案八:EAVS2005解决方案九:引用5楼loveskygirl521的回复: 什么啊?我问用什么建模工具??不是VS版本 MicrosoftVisio2005简称

js 加debugger调试提示无可用来源是怎么回事(C# MVC)

问题描述 js 加debugger调试提示无可用来源是怎么回事(C# MVC) 解决方案 用IE F12的js debugger能调试么?IE是否禁用了调试. 解决方案二: 动态加载的js会有这种现象.

将不确定变为确定~一切归总为“二”(C#中的位运算有啥用)

本文中的"二",指的是二进制,即看见2就进一,也叫逢二进一,它是最为简单和清晰的数据,在现实生活中,人们用的最多的就是十进制数据,即逢十进一,看一下例子: 二进制: 十进制 0                         0 01 01 10 02 11 03 100 04 看到了吧,在二进制中,不会出现比1大的数,除了0就是1,而在十进制中,不会出现10,它由0~9这10个数字组成. 在我们的C#中,位运算分为左位移和右位移,分别用<<和>>表示,左移相当

直接调试就可以正常运行,但是直接运行(不调试)就会出现错误

问题描述 我点击调试按钮程序却可以正常运行,但是点击开始执行(不调试)却出现下面的错误今天我在运行C#程序时,遇到了:值不能为空,参数名:path的错误详细信息是:System.ArgumentNullException:值不能为空.参数名:path在System.IO.StreamWriter..ctor(Stringpath,Booleanappend,Encodingencoding,Int32bufferSize)在System.IO.StreamWriter..ctor(Stringp

&amp;gt; 第七章 异常处理(rainbow 翻译) (来自重粒子空间)

<<展现C#>> 第七章 异常处理(rainbow 翻译) 出处:http://www.informit.com/matter/ser0000002 正文: 第七章   异常处理     通用语言运行时(CLR)具有的一个很大的优势为,异常处理是跨语言被标准化的.一个在C#中所引发的异常可以在Visual Basic客户中得到处理.不再有 HRESULTs  或者 ISupportErrorInfo 接口.    尽管跨语言异常处理的覆盖面很广,但这一章完全集中讨论C#异常处理.你