设为首页
收藏本站
最近更新

文章搜索
本类热门

首页 >> 网络编程 >> ASP.NET >> ASP.NET实例 >> 新闻正文 [字体: ] [打印文档]
ASP.NET高级教程—基类设计

文章作者:
责任编辑:rosan 录入时间:2007-6-15 9:14:24 来源:
频道声明:本频道的文章除部分特别声明禁止转载的专稿外,可以自由转载.但请务必注明出出处和原始作者 文章版权归本频道与文章作者所有.对于被频道转载文章的个人和网站,我们表示深深的谢意.

百特科技[http://www.PCbyte.cn]专业的空间、主机提供商,域名注册绝对优惠!
System.Text.RegularExpressions Imports System.Collections Imports Microsoft.VisualBasic namespace CjjerBase Public Class bbCode shared public Function GetBbcode(byref str as string ) as string Dim objregex as Regex ' Dim expressdata as string () ' Dim replacedata as string () ' ' expressdata = new string () { "(\[b\])(.*?)(\[\/b\])" ,"(\[i\])(.*?)(\[\/i\])","(\[code\])(.*)(\[/code\])","(\[color=(.[^\[]*)\])(.[^\[]*)(\[\/color\])"} ' replacedata = new string () { "<strong>$2</strong>", "<i>$2</i>" ,"<div class=""code"">$2</div>","<font color=$2>$3</font>"} Dim expressdata , replacedata as ArrayList expressdata = new ArrayList(4)'这个必添,节省资源 with expressdata .add ("(\[b\])(.*?)(\[\/b\])")'0 .add ("(\[i\])(.*?)(\[\/i\])") .add ("(\[code\])(.*)(\[/code\])") .add ("(\[color=(.[^\[]*)\])(.[^\[]*)(\[\/color\])")'3 End with replacedata = new ArrayList(4)'这个必添,节省资源 with replacedata .add ("<strong>$2</strong>")'0 .add ("<i>$2</i>") .add ("<div class=""code"">$2</div>") .add ("<font color=$2>$3</font>")'3 End with Dim e_ex as IEnumerator = expressdata.GetEnumerator Dim e_re as IEnumerator = replacedata.GetEnumerator Dim new_str as string = GetHtmlcode( str ) do while e_ex.movenext() and e_re.movenext() objregex = new Regex( e_ex.Current,RegexOptions.IgnoreCase ) new_str = objregex.replace(new_str,e_re.Current ) loop return new_str End Function shared public Function GetHtmlcode (byref str as string) as string Dim new_str as string = str ' new_str = Server.HtmlEncode(str) new_str = new_str.Replace( CHR(60), "&lt;")'左边的< new_str = new_str.Replace(CHR(62), "&gt;")'右边的> new_str = new_str.Replace( CHR(10), "<br/>") new_str = new_str.Replace(CHR(32), "&nbsp;") new_str = new_str.Replace(CHR(9), "&nbsp;") new_str = new_str.Replace(CHR(34), "&quot;") new_str = new_str.Replace(CHR(39), "&#39;") return new_str End Function End Class End namespace
[Ctrl+A 全部选择 然后拷贝]

其中做了一个几个最基本的转换,读者可以调用任何数据格式加载到UBB中的,其中核心的是:

  Dim  objregex as Regex
  Dim expressdata , replacedata  as ArrayList
'这里可以加载你的ubb转换的正则算式
  Dim e_ex as IEnumerator = expressdata.GetEnumerator
  Dim e_re as IEnumerator = replacedata.GetEnumerator
  
  Dim new_str as string = GetHtmlcode( str )
  do while e_ex.movenext() and  e_re.movenext()
   objregex = new Regex( e_ex.Current,RegexOptions.IgnoreCase )
   new_str = objregex.replace(new_str,e_re.Current  )
  loop

  return  new_str

注意,这里我一般只使用共享方法:

 shared public Function GetBbcode(byref str as string ) as string

其中传入的参数是引用,这样速度更快,因为一般的说来,需要转化的字符串较长,这点还是重要的。

此新闻共有3页 上一页 1 2 3 下一页

推荐好友 | 频道收藏 | 打印文档 | 报告错误  
相关连接
·[.net]windows控件实现水印
·ASP.NET高级教程—显示留言,分页
·ASP.NET高级教程—用户控件设计
·ASP.NET高级教程—基类设计
·ASP.NET高级教程—程序之规划篇
·ASP.NET高级教程—实战篇
·ASP.NET2.0里的配置接口API
·根据身份证判断性别和生日
同一专题
·无相关专题
发表评论 版权声明:除部分特别声明不要转载,或者授权我站独家播发的文章外,大家可以自由转载我站点的原创文章,但原作者和来自我站的链接必须保留(非我站原创的,按照原来自一节,自行链接)。文章版权归我站和作者共有
转载
要求转载之图片、文件,链接请不要盗链到本站,且不准打上各自站点的水印,亦不能抹去我站点水印。
共有评论查看评论
姓名: