vbscript5中增加了許多新功能,最振奮人心的當屬類和正規表示式的出現。以下是本人寫的乙個解析html**的類。我是
學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 = "" & vbcrlf
dim regex , regval , match , i
set regex = new regexp
regex.pattern = "<([a-z]/w*)(?:.*?)>(.*)"
regex.global = myglobal
regex.ignorecase = myignorecase
set regval = regex.execute(trim(input))
if regval.count > 0 then '如果發現匹配元素
parse = parse & "發現" & regval.count & "個html標記" & vbcrlf
parse = parse & "編號
匹配標記匹配顯示
" & vbcrlf
for i=0 to regval.count-1
set match = regval(i)
parse = parse & "" & vbcrlf
parse = parse & "" & i+1 & "
" & match.submatches(0) & "
" & match
& "" & vbcrlf
parse = parse & "" & vbcrlf
next
else parse = parse & "沒有發現html標記" & vbcrlf
end if
parse = parse & "" & vbcrlf
end function
'解析指定html標記的函式
public function parsetag(input,tag)
parsetag = "" & vbcrlf
dim regex , regval , match , i
set regex = new regexp
regex.pattern = "<(" & tag & ")(?:.*?)>(.*?)"
regex.global = myglobal
regex.ignorecase = myignorecase
set regval = regex.execute(trim(input))
if regval.count > 0 then '如果發現匹配元素
parsetag = parsetag & "發現" & regval.count & "個" & ucase(tag) & "標記" &
vbcrlf
parsetag = parsetag & "編號
發現位置包含內容
" &
vbcrlf
for i=0 to regval.count-1[page]
set match = regval(i)
parsetag = parsetag & "" & vbcrlf
parsetag = parsetag & "" & i+1 & "
" & match.firstindex & "
" &
match.submatches(1) & "" & vbcrlf
parsetag = parsetag & "" & vbcrlf
next
else parsetag = parsetag & "沒有發現" & ucase(tag) & "標記" & vbcrlf
end if
parsetag = parsetag & "" & vbcrlf
end function
'列印錯誤
private sub halt(errstr)
response.write("" & errstr & "" & vbcrlf)
call class_terminate
end sub
private sub class_terminate ' 設定 terminate 事件。
end sub
'定義兩個內部變數
private myglobal
private myignorecase
end class
%>
<%
'範例1
dim input , result
input = "這是乙個vbscript的正規表示式範例。"
set hp = new htmlparse
hp.global = 1
hp.ignorecase = false
result = hp.parse(input)
response.write(result)
%>
<%
'範例2
'hp.global = 1
'hp.ignorecase = false
result2 = hp.parsetag(input,"i")
response.write(result2)
set hp = nothing
%>
ASP中使用類
class webuser public property get islogin username if username then islogin true else islogin false jstz 請您先登入 login.htm end if end property public pr...
在ASP中使用儲存過程
學習使用儲存過程 stored procedure 是asp程式設計師的必須課之一。所有的大型資料庫都支援儲存過程,比如oracle ms sql等,但ms access不支援,不過,在access裡可以使用引數化的查詢 使用儲存過程有許多好處,它可以封裝複雜的資料邏輯,充分發揮大型資料庫本身的優勢...
在ASP中使用儲存過程
學習使用儲存過程 stored procedure 是asp程式設計師的必須課之一。所有的大型資料庫都支援儲存過程,比如oracle ms sql等,但ms access不支援,不過,在access裡可以使用引數化的查詢 使用儲存過程有許多好處,它可以封裝複雜的資料邏輯,充分發揮大型資料庫本身的優勢...