ASP中几个有用的函数
2006-05-09 14:31
477 查看
/* written by Jaron ,2003-6-8 */
/* 原出处:江都资讯网论坛 http://www.jiangdu.net/bbs */
/* 转载请注明出处和保留此版权信息 */
/* 欢迎使用SiteManager网站管理系统 http://sitemanager.cnzone.net */
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>的标记全部删除。
/* 原出处:江都资讯网论坛 http://www.jiangdu.net/bbs */
/* 转载请注明出处和保留此版权信息 */
/* 欢迎使用SiteManager网站管理系统 http://sitemanager.cnzone.net */
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>的标记全部删除。
相关文章推荐
- ASP中有关字符编码转换的几个有用函数
- ASP关于编码的几个有用的函数小结(utf8)
- ASP关于编码的几个有用的函数小结(utf8)
- ASP中几个有用的函数
- ASP中几个有用的函数
- ASP中几个有用的函数
- ASP中有关字符编码转换的几个有用函数
- ASP几个函数(返回汉字首字拼音/过滤HTML字符/检查组件是否已经安装/过滤特殊字符)
- asp.net过滤HTML标签的几个函数
- 介绍几个ASP.NET中容易忽略但却很重要的方法函数
- 再发几个ASP不错的函数
- Asp中有关字符编码转换的几个函数
- 几个有用的函数:
- asp几个转码函数
- oracle 几个有用但不常用的函数
- ASP采集入库生成本地文件的几个函数
- c里常见的几个有用的函数总结
- 介绍几个ASP.NET中容易忽略但却很重要的方法函数
- Asp.net中数字的字符串转换数值的几个常用函数(留着备用)