asp常用函数

//*****************************inarray函数

Function InArray(elem, arr)
If IsArray(arr) then
dim i
For i = 0 to UBound(arr)
If arr(i) = elem Then
InArray = i
Exit Function
End If
Next
End if
InArray = -1
End Function

案列:
str=”11,22,33,44,55,66″
str2=”11,33″
aaa=split(str,”,”)
bbb=split(str2,”,”)
for i=0 to ubound(aaa)
if inarray(aaa(i),bbb)<>-1 then
response.Write(aaa(i)&”<br/>”)
else
response.Write(aaa(i))
end if
next

//**********************************************************asp正则替换

Function huxiang(apos,apat,ares)
Set FSO = CreateObject(“Scripting.FileSystemObject”)
ss=server.MapPath(apos)
Set objFile = FSO.OpenTextFile(ss)
strContent = objFile.Readall

objFile.Close
Set objRegEx = CreateObject(“VBScript.RegExp”)
objRegEx.Global = True
objRegEx.IgnoreCase = True
objRegEx.Pattern = apat
objNewText = objRegEx.Replace(strContent,ares)
Set objTextFile = FSO.CreateTextFile(ss)
objTextFile.Write objNewText
objTextFile.Close
Set FSO = Nothing
End Function
案列
function huidiqu()

apos=”cangku/about/about_238.htm”
apat=”list\/\?(\d{1,3})\_(\d{1,3})\.html”
ares=”cangku/list/list_$1_$2.htm”

huxiang apos,apat,ares

end function
//***********************************************************获取网页一套
sub doindex()
Curl=site&”index.asp”
read=getHTTPPage(Curl)
if read<>”” then
  content=read
  call makeindex()
end if
end sub

sub makeindex()
  Set Fso = Server.CreateObject(“Scripting.FileSystemObject”)
  Filen=Server.MapPath(“cangku/index.htm”)
  Set Site_Config=FSO.CreateTextFile(Filen,true, False)
  Site_Config.Write content
  Site_Config.Close
  Set Fso = Nothing
 
end sub

Function getHTTPPage(url)
  dim http
  set http=Server.createobject(“Microsoft.XMLHTTP”)
  Http.open “GET”,url,false
  Http.send()
  if Http.readystate<>4 then
    exit function
  end if
  getHTTPPage=bytesToBSTR(Http.responseBody,”GB2312″)
  set http=nothing
  if err.number<>0 then err.Clear
End function
Function  BytesToBstr(body,Cset)
        if lenb(body)=0  then
           BytesToBstr=””
           exit  function
        end if
        dim mystream
        set mystream=server.createobject(“adodb.stream”)
        mystream.type=2
        mystream.mode=3
        mystream.open
        mystream.writetext body
        mystream.position=0
        mystream.charset=Cset
        mystream.position=2
        bstr=mystream.readtext()
        mystream.close
        set mystream=nothing
        BytesToBstr=bstr
End Function

//*********************************************************文件与文件夹操作请参考fso.asp类

此条目发表在asp参考分类目录。将固定链接加入收藏夹。

发表评论

邮箱地址不会被公开。 必填项已用*标注

您可以使用这些HTML标签和属性: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>