• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

转UBBC#完整

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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(" ","&nbsp;");
  
#endregion

  
#region 处理单引号
   sDetail
= sDetail.Replace("'","");
  
#endregion

  
#region 处理双引号
   sDetail
= sDetail.Replace("\"","&quot;");
  
#endregion

  
#region html标记符
   sDetail
= sDetail.Replace("<","&lt;");
   sDetail
= sDetail.Replace(">","&gt;"
);
  
  
#endregion

  
#region 处理换行
  
//处理换行,在每个新行的前面添加两个全角空格
   r = new Regex(@"(\r\n((&nbsp;)| )+)(?<正文>\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

  
#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标记
  
//标记
   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\">"
+
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\">"
+
 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\">" +

     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\">" +

     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[


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap