ubbcode的代码

  1. ubbcode.cs:
  2. using System; 
  3. using System.Data; 
  4. using System.Web.UI; 
  5. using System.Web.UI.WebControls; 
  6. using System.Web.UI.HtmlControls; 
  7. using System.Text.RegularExpressions ; 
  8. using System.Text; 
  9. using System.Collections ; 
  10.  
  11. namespace gb
  12. {
  13.     /// <summary>
  14.     /// Summary description for ubbcode.
  15.     /// </summary>
  16.     public class ubbcode
  17.     {
  18.         public ubbcode()
  19.         {
  20.             // TODO: Add constructor logic here
  21.         }
  22.             public string changechr(string chr)
  23.         {
  24.             if(chr==null)
  25.                 return "";
  26.                 chr=chr.Replace("<","<");
  27.                 chr=chr.Replace(">",">");
  28.                 chr=chr.Replace("/n","<br>");
  29.                 chr = Regex.Replace(chr,@"<script(?<x>[^/>]*)>(?<y>[^/>]*)/</script/>",@"<script$1>$2</script>",RegexOptions.IgnoreCase);
  30.                 chr = Regex.Replace(chr,@"/[url=(?<x>[^/]]*)/](?<y>[^/]]*)/[/url/]",@"<a href=$1 target=_blank>$2</a>",RegexOptions.IgnoreCase);
  31.                 chr = Regex.Replace(chr,@"/[url/](?<x>[^/]]*)/[/url/]",@"<a href=$1 target=_blank>$1</a>",RegexOptions.IgnoreCase);
  32.                 chr = Regex.Replace(chr,@"/[email=(?<x>[^/]]*)/](?<y>[^/]]*)/[/email/]",@"<a href=$1>$2</a>",RegexOptions.IgnoreCase);
  33.                 chr = Regex.Replace(chr,@"/[email/](?<x>[^/])*)/[/email/]",@"<a href=$1>$1</a>",RegexOptions.IgnoreCase);
  34.                 chr = Regex.Replace(chr,@"/[flash](?<x>[^/]]*)/[/flash]",@"<OBJECT codeBase=http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=4,0,2,0 classid=clsid:D27CDB6E-AE6D-11cf-96B8-444553540000 width=500 height=400><PARAM NAME=movie VALUE=""$1""><PARAM NAME=quality VALUE=high><embed src=""$1"" quality=high pluginspage='http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash' type='application/x-shockwave-flash' width=500 height=400>$1</embed></OBJECT>",RegexOptions.IgnoreCase);
  35.                     chr = Regex.Replace(chr,@"/[img](?<x>[^/]]*)/[/img]",@"<IMG SRC=""$1"" border=0>",RegexOptions.IgnoreCase);
  36.                 chr = Regex.Replace(chr,@"/[color=(?<x>[^/]]*)/](?<y>[^/]]*)/[/color/]",@"<font color=$1>$2</font>",RegexOptions.IgnoreCase);
  37.                 chr = Regex.Replace(chr,@"/[face=(?<x>[^/]]*)/](?<y>[^/]]*)/[/face/]",@"<font face=$1>$2</font>",RegexOptions.IgnoreCase);
  38.                 chr = Regex.Replace(chr,@"/[size=1/](?<x>[^/]]*)/[/size/]",@"<font size=1>$1</font>",RegexOptions.IgnoreCase);
  39.                 chr = Regex.Replace(chr,@"/[size=2/](?<x>[^/]]*)/[/size/]",@"<font size=2>$1</font>",RegexOptions.IgnoreCase);
  40.                 chr = Regex.Replace(chr,@"/[size=3/](?<x>[^/]]*)/[/size/]",@"<font size=3>$1</font>",RegexOptions.IgnoreCase);
  41.                 chr = Regex.Replace(chr,@"/[size=4/](?<x>[^/]]*)/[/size/]",@"<font size=4>$1</font>",RegexOptions.IgnoreCase);
  42.                 chr = Regex.Replace(chr,@"/[align=(?<x>[^/]]*)/](?<y>[^/]]*)/[/align/]",@"<align=$1>$2</align>",RegexOptions.IgnoreCase);
  43.                 chr = Regex.Replace(chr,@"/[fly](?<x>[^/]]*)/[/fly]",@"<marquee width=90% behavior=alternate scrollamount=3>$1</marquee>",RegexOptions.IgnoreCase);
  44.                 chr = Regex.Replace(chr,@"/[move](?<x>[^/]]*)/[/move]",@"<marquee scrollamount=3>$1</marquee>",RegexOptions.IgnoreCase);
  45.                 chr = Regex.Replace(chr,@"/[glow=(?<x>[^/]]*),(?<y>[^/]]*),(?<z>[^/]]*)/](?<w>[^/]]*)/[/glow/]",@"<table width=$1 style='filter:glow(color=$2, strength=$3)'>$4</table>",RegexOptions.IgnoreCase);
  46.                 chr = Regex.Replace(chr,@"/[shadow=(?<x>[^/]]*),(?<y>[^/]]*),(?<z>[^/]]*)/](?<w>[^/]]*)/[/shadow/]",@"<table width=$1 style='filter:shadow(color=$2, strength=$3)'>$4</table>",RegexOptions.IgnoreCase);
  47.                 chr = Regex.Replace(chr,@"/[b/](?<x>[^/]]*)/[/b/]",@"<b>$1</b>",RegexOptions.IgnoreCase);
  48.                 chr = Regex.Replace(chr,@"/[i/](?<x>[^/]]*)/[/i/]",@"<i>$1</i>",RegexOptions.IgnoreCase);
  49.                 chr = Regex.Replace(chr,@"/[u/](?<x>[^/]]*)/[/u/]",@"<u>$1</u>",RegexOptions.IgnoreCase);
  50.                 chr = Regex.Replace(chr,@"/[code/](?<x>[^/]]*)/[/code/]",@"<pre id=code><font size=1 face='Verdana, Arial' id=code>$1</font id=code></pre id=code>",RegexOptions.IgnoreCase);
  51.                 chr = Regex.Replace(chr,@"/[list/](?<x>[^/]]*)/[/list/]",@"<ul>$1</ul>",RegexOptions.IgnoreCase);
  52.                 chr = Regex.Replace(chr,@"/[list=1/](?<x>[^/]]*)/[/list/]",@"<ol type=1>$1</ol id=1>",RegexOptions.IgnoreCase);
  53.                 chr = Regex.Replace(chr,@"/[list=a/](?<x>[^/]]*)/[/list/]",@"<ol type=a>$1</ol id=a>",RegexOptions.IgnoreCase);
  54.                 chr = Regex.Replace(chr,@"/[/*/](?<x>[^/]]*)/[//*/]",@"<li>$1</li>",RegexOptions.IgnoreCase);
  55.                 chr = Regex.Replace(chr,@"/[quote](?<x>.*)/[/quote]",@"<center>—— 以下是引用 ——<table border='1' width='80%' cellpadding='10' cellspacing='0' ><tr><td>$1</td></tr></table></center>",RegexOptions.IgnoreCase);
  56.             return(chr);
  57.         }
  58.     }
  59. }
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值