当前位置:编程学习 > asp >>

asp 获取字符串中url地址函数

asp教程 获取字符串中url地址函数
'本文章提供了三款利用asp的正则获取字符串中url地址自定义函数哦,三个方法的实现原理都是获取以http开的url地址哦。
on error goto z
'

dim url,key,wwwname
url=request.servervariables("server_name")
if instr(url,".")>0 then
key=split(url,".")
wwwname=key(0)
wwwname=replace(wwwname,"http://","")
end if
response.write(wwwname)

'方法二

'vb.net:
public shared function isurl(byval strtmp as string) as boolean
on error goto z
dim objintpattern as new system.text.regularexpressions.regex( "^(http://|https教程://){0,1}[a-za-z0-9][a-za-z0-9-.]+[a-za-z0-9].[a-za-z]{2,}[43-176]*$")
return objintpattern.ismatch(strtmp)
z:
end function

private sub button1_click(byval sender as system.object, byval e as system.eventargs) handles button1.click
msgbox (isurl( "http://www.sohu.com"))

'方法三

dim objintpattern
isurl = false
set objintpattern = new regexp
objintpattern.pattern = "^(http://|https://){0,1}[a-za-z0-9][a-za-z0-9-.]+[a-za-z0-9].[a-za-z]{2,}[43-176]*$"
objintpattern.global = true
isurl = objintpattern.test(strtmp)
set objintpattern = nothing
z:
end function

private sub command1_click()
msgbox isurl( "http://www.sohu.com")
end sub

补充:asp教程,ASP入门 
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,