ASP中幾個有用的函數

來源:互聯網
上載者:User

function DeleteFile(Filename) '刪除檔案
 if Filename<>"" then
  Set fso = server.CreateObject("Scripting.FileSystemObject")
  if fso.FileExists(Filename) then
   fso.DeleteFile Filename
  end if
  set fso = nothing
 end if
end function

function CreateDIR(byval LocalPath) '建立目錄的程式,如果有多級目錄,則一級一級的建立
 on error resume next
 LocalPath = replace(LocalPath,"\","/")
 set FileObject = server.createobject("Scripting.FileSystemObject")
 patharr = split(LocalPath,"/")
 path_level = ubound(patharr)
 for i = 0 to path_level
  if i=0 then pathtmp=patharr(0) & "/" else pathtmp = pathtmp & patharr(i) & "/"
  cpath = left(pathtmp,len(pathtmp)-1)
  if not FileObject.FolderExists(cpath) then FileObject.CreateFolder cpath
 next
 set FileObject = nothing
 if err.number<>0 then
  CreateDIR = false
  err.Clear
 else
  CreateDIR = true
 end if
end function

function GenerateRandomFileName(byval szFilename) '根據原檔案名稱產生新的隨機檔案名稱
 randomize
 ranNum=int(90000*rnd)+10000
 if month(now)<10 then c_month="0" & month(now) else c_month=month(now)
 if day(now)<10 then c_day="0" & day(now) else c_day=day(now) 
 if hour(now)<10 then c_hour="0" & hour(now) else c_hour=hour(now)
 if minute(now)<10 then c_minute="0" & minute(now) else c_minute=minute(now)
 if second(now)<10 then c_second="0" & second(now) else c_second=minute(now)
 fileExt_a=split(szFilename,".")
 fileExt=lcase(fileExt_a(ubound(fileExt_a)))
 GenerateRandomFileName = year(now)&c_month&c_day&c_hour&c_minute&c_second&"_"&ranNum&"."&fileExt
end function

function jaron_replacer(strContent,start_string,end_string,replace_string)
 'CMS替換函數:源字串,前部分,後部分,替換成的字元
 '返回被替換後的字串
 jaron_replacer = replace(strContent,mid(strContent,instr(strContent,start_string),instr(strContent,end_string)+len(end_string)-1),replace_string)
end function

function replaceplus(strContent,start_string,end_string,replace_string) '文檔中,將所有開始,結束之間的所有字元刪除
on error resume next
MARKCOUNTS = ubound(split(strContent,start_string))
PRESTRING = strContent
for i=0 to MARKCOUNTS
STARTMARK=instr(1,PRESTRING,start_string,1)
if STARTMARK=0 then exit for
COMPMARK=instr(1,PRESTRING,end_string,1) + len(end_string)
VerString=mid(PRESTRING,STARTMARK,COMPMARK - STARTMARK)
PRESTRING = replace(PRESTRING,VerString,replace_string)
next
replaceplus = PRESTRING
if err.number<>0 then err.Clear
end function

如果在一段HTML中,你並不知道裡面有多少個FLASH,想把他們全部刪除。就可以這樣用。

strContent = replaceplus(strContent,"<OBJECT","</OBJECT>","")

這個命令可以把HTML代碼中所有<object> .... </object>的標記全部刪除。

 
 
 



相關文章

Beyond APAC's No.1 Cloud

19.6% IaaS Market Share in Asia Pacific - Gartner IT Service report, 2018

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。