Several useful functions in ASP

Source: Internet
Author: User

Function DeleteFile (Filename) ' Delete file
 if filename<> ' then
  Set FSO = server. CreateObject ("Scripting.FileSystemObject")
  if FSO. FileExists (Filename) then
   FSO. DeleteFile Filename
  End If
  Set fso = no
 end if
End Function

Function Createdir (ByVal localpath) ' The program that creates the directory, if there is a multilevel directory, the first-level creation
 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 the N Pathtmp=patharr (0) & "/" Else Pathtmp = pathtmp & Patharr (i) & "/"
  CPath = Left (Pathtmp,len (pathtm P)-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) ' generates a new random filename based on the original file name
 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 ' 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 replacement function: Source string, front section, back section, replaced by character
' Returns the replaced string
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) ' Document to remove all the characters between the start and end
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

If you are in a section of HTML, you do not know how many flash inside, you want to remove them all. Can be used in this way.

Strcontent = Replaceplus (strcontent, "<object", "</OBJECT>", "")

This command deletes all the tags in the HTML code for all <object> ... </object>.






Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.