国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 開發 > 綜合 > 正文

UBB(c#完整版)

2024-07-21 02:17:45
字體:
來源:轉載
供稿:網友

最近我又開始用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(" ","&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;)| )+)(?<正文> +)",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/])([ /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/])([ /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/])([ /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 處[url][/url]標記
   //處[url][/url]標記
   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 處[url=xxx][/url]標記
   //處[url=xxx][/url]標記
   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 處[email][/email]標記
   //處[email][/email]標記
   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 處[email=xxx][/email]標記
   //處[email=xxx][/email]標記
   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 處[size=x][/size]標記
   //處[size=x][/size]標記
   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 處[color=x][/color]標記
   //處[color=x][/color]標記
   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("http://[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 處理[list=x][*][/list]
   //處理[list=x][*][/list]
   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 處[center][/center]標記
   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
 }
}



發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 穆棱市| 弥渡县| 黎平县| 砚山县| 林甸县| 海南省| 衡山县| 忻州市| 墨竹工卡县| 剑阁县| 天气| 津南区| 肇东市| 临清市| 巴塘县| 南澳县| 罗源县| 西藏| 合山市| 蓬莱市| 霍城县| 泗洪县| 富宁县| 西乌| 茌平县| 北碚区| 广西| 庆元县| 日土县| 开江县| 涟源市| 连平县| 西安市| 竹山县| 大余县| 福清市| 酉阳| 新河县| 拜泉县| 孝昌县| 疏勒县|