上一篇:使用组件搜索 >>
在ASP中使用类
学php的,语法有不习惯的地方,请大家多包含。
<%
class htmlparse
设置 initialize 事件。
private sub class_initialize
myglobal = true
myignorecase = true
end sub
property let global(g)
dim regex 建立变量。
set regex = new regexp 建立正则表达式。
regex.pattern = "true|false|1|0" 设置模式。
regex.ignorecase = true 设置是否区分大小写。
if regex.test(cstr(g)) then
myglobal = g
else
call halt("无效global参数配置")
end if
end property
property get global()
global = myglobal
end property
property let ignorecase(c)
dim regex
set regex = new regexp
regex.pattern = "true|false|1|0"
regex.ignorecase = true
if regex.test(cstr(c)) then
myignorecase = c
else
call halt("无效ignorecase参数配置")
end if
end property
property get ignorecase()
ignorecase = myignorecase
end property
解析所有html标记的函数
public function parse(input)
parse = "<table border=1 width=50% align=center>" & vbcrlf
dim regex , regval , match , i
set regex = new regexp
regex.pattern = "<([a-z]\w*)(?:.*?)>(.*)<\/\1>"
regex.global = myglobal
regex.ignorecase = myignorecase
set regval = regex.execute(trim(input))
if regval.count > 0 then 如果发现匹配元素
parse = parse & "<caption>发现" & regval.count & "个html标记</caption>" & vbcrlf
parse = parse & "<tr align=center><th>编号</th><th>匹配标记<th>匹配显示</th></tr>" & vbcrlf
for i=0 to regval.count-1
set match = regval(i)
parse = parse & "<tr align=center>" & vbcrlf
parse = parse & "<td>" & i+1 & "</td><td>" & match.submatches(0) & "</td><td>" & match
& "</td>" & vbcrlf
parse = parse & "</tr>" & vbcrlf
next
else parse = parse & "<caption>没有发现html标记</caption>" & vbcrlf
end if
parse = parse & "</table>" & vbcrlf
end function
解析指定html标记的函数
public function parsetag(input,tag)
parsetag = "<table border=1 width=50% align=center>" & vbcrlf
dim regex , regval , match , i
set regex = new regexp
regex.pattern = "<(" & tag & ")(?:.*?)>(.*?)<\/\1>"
regex.global = myglobal
regex.ignorecase = myignorecase
set regval = regex.execute(trim(input))
if regval.count > 0 then 如果发现匹配元素
parsetag = parsetag & "<caption>发现" & regval.count & "个" & ucase(tag) & "标记</caption>" &
vbcrlf
parsetag = parsetag & "<tr align=center><th>编号</th><th>发现位置<th>包含内容</th></tr>" &
vbcrlf
for i=0 to regval.count-1
set match = regval(i)
parsetag = parsetag & "<tr align=center>" & vbcrlf
parsetag = parsetag & "<td>" & i+1 & "</td><td>" & match.firstindex & "</td><td>" &
match.submatches(1) & "</td>" & vbcrlf
parsetag = parsetag & "</tr>" & vbcrlf
next
else parsetag = parsetag & "<caption>没有发现" & ucase(tag) & "标记</caption>" & vbcrlf
end if
parsetag = parsetag & "</table>" & vbcrlf
end function
打印错误
private sub halt(errstr)
response.write("<font color=red size=3>" & errstr & "</font>" & vbcrlf)
call class_terminate
end sub
private sub class_terminate 设置 terminate 事件。
end sub
定义两个内部变量
private myglobal
private myignorecase
end class
%>
<html>
<body>
<div align=center><h2>范例1</h2></div>
<%
范例1
dim input , result
input = "<i>这是</i>一个<font color=green>vbscript</font>的<b>正则<i>表达式</i>范例</b>。"
set hp = new htmlparse
hp.global = 1
hp.ignorecase = false
result = hp.parse(input)
response.write(result)
%>
<br>
<div align=center><h2>范例2</h2></div>
<%
范例2
hp.global = 1
hp.ignorecase = false
result2 = hp.parsetag(input,"i")
response.write(result2)
set hp = nothing
%>
</body>
</html>
大家应该注意到了,vbscript的正则表达式和jscript的解析是一样的,只是语法不同。关于最新的vbscript的文档,大家
可以到微软中国的脚本技术主页去下载,网址:http://www.microsoft.com/china/scripting
()
下一篇:利用JDBC连接MS SQL Ser2000+sp2 >>
相关文章:
- · 关于页面缓存清除的方法小结(整理)
- · 用ASP随机产生随机数
- · 在您的网站中加入互动功能
- · 用ASP实现对ORACLE数据库的操作
- · 用正则解析图片地址并利用XMLHTTP组件将其保存是个好东西哦
- · 无组件上传图片至SQLSERVER数据库示例
- · 起泡法按照时间排列文件(FSO)
- · 随机顺序显示代
- · 教你5分钟做成一个ASP论坛
- · 把UTF-8编码转换为GB2312编码
- · 在asp中加密与解密对应的函数
- · 用ASP将数据读数导出EXCEL文件的四种方法
- · 一个ASP版的图片浏览器
- · 如何准确定时运行ASP文件
- · 实现UBB代码
- · ASP编程技巧大全
- · 最近才发现我的程序里有如此多的漏洞
- · 创建ASP组件修改《SERV-U》FTP 的密码
- · 多级选择问题的ASP实现可以入精华吗
- · 我有一个加密方法,欢迎大家指正
- · 用asp整理磁盘文件
- · 判断一个字符串里面包含有中文或者英文
- · 贴上一贴:GB码和BIG5码的互换技术
- · 加亮显示ASP文章原代码
- · ASP Error 0115的一些解决办法调用组件出错
- · 如何Response.Redirect新的页面到指定的框架中(转)
- · 图片的导入导出
- · 做下载时,对中文名的处理办法
- · ASP页面内VBScript和JScript的交互(转)
- · 不刷新页面改变下拉菜单内容
- · 如何用ASP建立图表
- · 一个查看ASP的JavaScript程序
- · 精华asp代码收集
- · Asp.Net下的DataGrid的多层表头
- · asp.net 中使用sqlcommandbuilder
- · 制作一个简单的服务器端控制
- · 从imobile.com.cn采集手机归属地的函数
- · 轻松学习XML教程
