您正在使用 IPV4 [18.117.107.90] 访问本站,您本次已经查看了 1 页
用户名: 密 码: 验证码:     用QQ登录本站
首页 软件 编程 笑话 知识 公告 台风 日历 计算器
[公益]保护绿色环境,构建和谐社会       悟空收录网      

【腾讯云】 爆款2核2G3M云服务器首年 61元,叠加红包再享折上折      
[公益] 地球是我家,绿化靠大家      
2024年 劳动节 012
2024年 端午节 052
2025年 元 旦 257
2025年 春 节 285
 
您现在的位置:首页 >> ASP/ASP.net >> 内容
本类新增
本类热门
asp之自动闭合HTML/ubb标签函数附简单注释
内容摘要: FunctioncloseUBB(strContent)'*************************************'自动闭合UBB'*************************************DimarrTags,i,OpenPos,ClosePos,re,strMatchs,j,MatchSetre=NewRegExp'申明......
FunctioncloseUBB(strContent)

'*************************************

'自动闭合UBB

'*************************************

DimarrTags,i,OpenPos,ClosePos,re,strMatchs,j,Match

Setre=NewRegExp'申明re对象

re.IgnoreCase=True'设置是否区分字符大小写

re.Global=True'设置全局可用性

arrTags=Array("code","quote","list","color","align","font","size","b","i","u","html")'建立数组,存储相关需要检测是否闭合的标签

Fori=0ToUBound(arrTags)'循环对数组里的每一个元素进行检测

OpenPos=0'初始化当前标签开始标记的个数

ClosePos=0'初始化当前标签结束标记的个数

re.Pattern="\["+arrTags(i)+"(=[^\[\]]+|)\]"'开始分别正则判断开始与结束标记的个数

SetstrMatchs=re.Execute(strContent)

ForEachMatchinstrMatchs

OpenPosOpenPos=OpenPos+1

Next

re.Pattern="\[/"+arrTags(i)+"\]"

SetstrMatchs=re.Execute(strContent)

ForEachMatchinstrMatchs

ClosePosClosePos=ClosePos+1

Next

Forj=1ToOpenPos-ClosePos'当开始与结束标记数量不一致时,闭合当前标签

strContentstrContent=strContent+"[/"+arrTags(i)+"]"

Next

Next

closeUBB=strContent

Setre=Nothing

EndFunction

程序代码

FunctioncloseHTML(strContent)

'*************************************

'自动闭合HTML

'*************************************

DimarrTags,i,OpenPos,ClosePos,re,strMatchs,j,Match

Setre=NewRegExp

re.IgnoreCase=True

re.Global=True

arrTags=Array("p","div","span","table","ul","font","b","u","i","h1","h2","h3","h4","h5","h6")

Fori=0ToUBound(arrTags)

OpenPos=0

ClosePos=0

re.Pattern="\<"+arrTags(i)+"([^\<\>]+|)\>"

SetstrMatchs=re.Execute(strContent)

ForEachMatchinstrMatchs

OpenPosOpenPos=OpenPos+1

Next

re.Pattern="\</"+arrTags(i)+"\>"

SetstrMatchs=re.Execute(strContent)

ForEachMatchinstrMatchs

ClosePosClosePos=ClosePos+1

Next

Forj=1ToOpenPos-ClosePos

strContentstrContent=strContent+"</"+arrTags(i)+">"

Next

Next

closeHTML=strContent

Setre=Nothing

EndFunction

下面的是pjblog的函数代码,但没有注释,学习研究建议参考上面的注释

复制代码代码如下:

'*************************************

'自动闭合UBB

'*************************************

FunctioncloseUBB(strContent)

DimarrTags,i,OpenPos,ClosePos,re,strMatchs,j,Match

Setre=NewRegExp

re.IgnoreCase=True

re.Global=True

arrTags=Array("code","quote","list","color","align","font","size","b","i","u","html")

Fori=0ToUBound(arrTags)

OpenPos=0

ClosePos=0

re.Pattern="\["+arrTags(i)+"(=[^\[\]]+|)\]"

SetstrMatchs=re.Execute(strContent)

ForEachMatchinstrMatchs

OpenPos=OpenPos+1

Next

re.Pattern="\[/"+arrTags(i)+"\]"

SetstrMatchs=re.Execute(strContent)

ForEachMatchinstrMatchs

ClosePos=ClosePos+1

Next

Forj=1ToOpenPos-ClosePos

strContent=strContent+"[/"+arrTags(i)+"]"

Next

Next

closeUBB=strContent

EndFunction

'*************************************

'自动闭合HTML

'*************************************

FunctioncloseHTML(strContent)

DimarrTags,i,OpenPos,ClosePos,re,strMatchs,j,Match

Setre=NewRegExp

re.IgnoreCase=True

re.Global=True

arrTags=Array("p","div","span","table","ul","font","b","u","i","h1","h2","h3","h4","h5","h6")

Fori=0ToUBound(arrTags)

OpenPos=0

ClosePos=0

re.Pattern="\<"+arrTags(i)+"([^\<\>]+|)\>"

SetstrMatchs=re.Execute(strContent)

ForEachMatchinstrMatchs

OpenPos=OpenPos+1

Next

re.Pattern="\</"+arrTags(i)+"\>"

SetstrMatchs=re.Execute(strContent)

ForEachMatchinstrMatchs

ClosePos=ClosePos+1

Next

Forj=1ToOpenPos-ClosePos

strContent=strContent+"</"+arrTags(i)+">"

Next

Next

closeHTML=strContent

EndFunction

版权声明:本内容来源于互联网,如有侵犯您的版权,请联系站长,本站收到您的信息后将及时处理。
上一篇:查看AspJpeg组件是否过期的方法

 

下一篇:随机提取Access/SqlServer数据库中的10条记录

发布日期:2022/3/28
手机扫二维码直达本页
发布时间:19:17:49
点  击:3
录  入:齐天大圣
相关文章
Baidu
YiJiaCMS 7.3.8 build231228(MSSQL) 闽ICP备05000814号-1
本空间由腾讯云(轻量应用服务器)提供,Cloudflare提供加速防护
运行时间载入中.....