ASP常用函数库Word格式文档下载.docx
《ASP常用函数库Word格式文档下载.docx》由会员分享,可在线阅读,更多相关《ASP常用函数库Word格式文档下载.docx(41页珍藏版)》请在冰豆网上搜索。
34:
45PM
其中
"
m"
="
month"
;
d"
day"
如果是currentDate格式,则,
h"
hour"
s"
second"
7.函数Datediff()
计算某量个指定的时间差
datediff(timeinterval,date1,date2[,firstdayofweek[,firstdayofyear]])
timeinterval是时间单位;
date1,date2是有效的日期表达式,firstdayofweek,firstdayofyear是任意选项.
Thereare150daystomilleniumfrom8/4/99.
8.函数day()
返回一个整数值,对应于某月的某日
day(date)
date是一个有效的日期表达式;
4
9.函数formatcurrency()
转换成货币格式
formatcurrency(expression[,digit[,leadingdigit[,paren[,groupdigit]]]])
expression是有效的数字表达式;
digit表示小数点后的位数;
leadingdigit,paren,groupdigit是任意选项.
$34.35
10.函数Formatdatetime()
格式化日期表达式/变量
formatdatetime(date[,nameformat])
date为有效的日期表达式/变量;
nameformat是指定的日期格式常量名称.
Wednesday,August04,1999
11.函数formatnumber()
格式化数字表达式/变量
formatnumbe(expression[,digit[,leadingdigit[,paren[,groupdigit]]]])
express为有效的数字表达式,digit表示小数点后的位数;
leadingdigit,paren,groupdigit是任意选项
23.222
12.函数formatpercent()
格式化百分数表达式/变量
formatnumber(expression[,digit[,leading[,paren[,groupdigit]]]])
expression是有效的数字表达式,digit表示小数点后的位数;
45.233
13.函数:
hour()
返回一个数值,对应于的指定时间.
hour(time)
time对应于的指定时间.
16(24小时制)
14.函数instr()
返回一个数值,对应于某字符(串)在另一字符串中的位置.
instr([start,]strtobesearched,strsearchfor[,compare])
start(任选)是从第start位寻找,strtobesearched是被搜索的字符串,strsearchfor是被寻找的目标.compare是任意选项
9,(字符"
a"
在strtext字符串的第九位)
15.函数instrrev()
返回一个数值,对应于某字符(串)在另一字符串中的位置(从后面起开始寻找).
instrrev([start,]strtobesearched,strsearchfor[,compare])
参考instr(),
13,字串"
是strtext的第13个字符(从后面起开始寻找)
16.函数int()
数字取整
int(number)
number是任何有效的数字表达式/其它类型的变量
322(如果用Cint()则结果是323)
17.函数isarray()
返回一个布尔值,判断变量是否为数组.
isarray(name)
name是变量名称
false
18.函数isdate()
返回一个布尔值,判断变量是否为日期变量.
isdate(expression)
expression是任意的变量.
true
19.函数isempty()
返回一个布尔值,判断变量是否为空.
isempty(expression)
20.函数isnull()
返回一个布尔值,判断变量是否包含非法的数据.
isnull(expression)
21.函数Isnumeric()
返回一个布尔值,判断变量是否为数字变量,或者是可以转换成数字的其它变量.
isnumeric(expression)
true.
22.函数Isobject()
返回一个布尔值,判断变量是否为对象的变量,
isobject(expression)
true
23.函数:
Lbound()
返回一个数组的下界.
Lbound(arrayname[,dimension])
arrayname是数组变量,dimension是任意项
0
24.函数Lcase()
将一字符类型变量的字符全部变换小写字符.
Lcase(string)
string是字串变量
thisislcase!
25.函数left()
截取一个字符串的前部分;
left(string,length)
string字符串,length截取的长度.
thisi
26.函数len()
返回字符串长度或者变量的字节长度
len(string|varname)
string字符串;
varname任意的变量名称
15
27.函数ltrim()
去掉字符串前的空格.
ltrim(string)
string字串.
Today
29.函数minute()
返回一数值,表示分钟
minute(time)
time是时间变量
23
30.函数month()
返回一数值,表示月份
month(time)
time是日期变量
9
31.函数monthname()
返回月份的字符串(名称).
Monthname(date[,abb])
date是日期变量,abb=true时则月份的缩写,
April
32.函数Now()
返回系统的当前时间和日期.
now()
05/10/008:
45:
32pm
33.函数:
replace()
在字串中查找,替代指定的字串.
replace(strtobesearched,strsearchfor,strreplacewith
[,start[,count[,compare]]])
strtobesearched是字串;
strsearchfor是被查找的子字串;
strreplacewith
是用来替代的子字串.start,count,compare是任意选项.
thisisanorange.
34.函数right()
截取一个字符串的后部分
right(string,length)
st!
35.函数rnd()
返回一个随机数值
rnd[(number)]
number是任意数值.
0/1数值之一,无randomize(),则不能产生随机数.
36.函数round()
完整数值
round(expression[,numright])
expression数字表达式;
numright任意选项.
12
37.函数rtrim()
去掉字符串后的空格.
rtrim(string)
string是字串
thisisatest!
38.函数second()
返回一个整数值.
second(time)
time是一个有效的时间表达式;
30
39.函数strReverse()
返回与原字串排列逆向的字串.
strreverse(string)
string是字串
40.重新设定图片大小,返回百分比
functionresizeImg(ox,oy,nx,ny)
resizeimg=1
Ifox<
=nxAndoy<
=nyThenExitfunction
dimx,y
'
先算x
x=ny*ox/oy
ifx>
nxthen'
x不行
y=nx*oy/ox
resizeImg=y/oy
else
resizeImg=x/ox
endif
resizeImg=formatNumber(resizeImg,4)
endfunction
41.上传时生成自动目录(以2005_6类似的名称)
FunctionmakeMonthDir(vitualRoot,virtual)
DimdirName,dirNameV,fso
dirNameV=vitualRoot&
"
/"
&
Year(Now())&
_"
Month(Now())
dirName=server.MapPath(dirNameV)
response.writeDirName&
<
br>
Setfso=server.CreateObject("
Scripting.FileSystemObject"
)
ifnotfso.FolderExists(dirName)then
fso.CreateFolder(dirName)
setfso=Nothing
IfvirtualThen
makeMonthDir=dirNameV&
Else
makeMonthDir=dirName&
\"
Endif
EndFunction
42.删除指定的文件,必须传入虚拟路径
SubDoDelFile(sPathFile)
OnErrorResumeNext
DimoFSO
SetoFSO=Server.CreateObject("
response.write"
Server.MapPath(sPathFile)
oFSO.DeleteFile(Server.MapPath(sPathFile))
SetoFSO=Nothing
EndSub
43.格式化时间(显示)
参数:
n_Flag
1:
yyyy-mm-ddhh:
mm:
ss"
2:
yyyy-mm-dd"
3:
hh:
4:
yyyy年mm月dd日"
5:
yyyymmdd"
6:
MM/DD"
============================================
FunctionFormat_Time(s_Time,n_Flag)
Dimy,m,d,h,mi,s
Format_Time="
IfIsDate(s_Time)=FalseThenExitFunction
y=cstr(year(s_Time))
m=cstr(month(s_Time))
Iflen(m)=1Thenm="
0"
m
d=cstr(day(s_Time))
Iflen(d)=1Thend="
d
h=cstr(hour(s_Time))
Iflen(h)=1Thenh="
h
mi=cstr(minute(s_Time))
Iflen(mi)=1Thenmi="
mi
s=cstr(second(s_Time))
Iflen(s)=1Thens="
s
SelectCasen_Flag
Case1
yyyy-mm-ddhh:
ss
Format_Time=y&
-"
m&
d&
h&
:
mi&
Case2
yyyy-mm-dd
Case3
hh:
Format_Time=h&
Case4
yyyy年mm月dd日
年"
月"
日"
Case5
yyyymmdd
Case6
mm/dd
Format_Time=m&
case7
right(y,2)
EndSelect
44.
把字符串进行HTML解码,替换server.htmlencode
去除Html格式,用于显示输出
FunctionoutHTML(str)
DimsTemp
sTemp=str
outHTML="
IfIsNull(sTemp)=TrueThen
ExitFunction
EndIf
sTemp=Replace(sTemp,"
&
"
>
sTemp=Replace(sTemp,Chr(34),"
sTemp=Replace(sTemp,Chr(10),"
outHTML=sTemp
EndFunction
45.
去除Html格式,用于从数据库中取出值填入输入框时
注意:
value="
?
这边一定要用双引号
FunctioninHTML(str)
inHTML="
inHTML=sTemp
46.
检测上页是否从本站提交
返回:
True,False
FunctionIsSelfRefer()
DimsHttp_Referer,sServer_Name
sHttp_Referer=CStr(Request.ServerVariables("
HTTP_REFERER"
))
sServer_Name=CStr(Request.ServerVariables("
SERVER_NAME"
IfMid(sHttp_Referer,8,Len(sServer_Name))=sServer_NameThen
IsSelfRefer=True
IsSelfRefer=False
47
得到安全字符串,在查询中使用
FunctionGet_SafeStr(str)
Get_SafeStr=Replace(Replace(Replace(Trim(str),"
),Chr(34),"
),"
48.
取实际字符长度
FunctionGet_TrueLen(str)
Diml,t,c,i
l=Len(str)
t=l
Fori=1Tol
c=Asc(Mid(str,i,1))
Ifc<
0Thenc=c+65536
Ifc>
255Thent=t+1
Next
Get_TrueLen=t
49.
判断是否安全字符串,在注册登录等特殊字段中使用
FunctionIsSafeStr(str)
Dims_BadStr,n,i
s_BadStr="
&
%,;
()`~!
@#$^*{}[]|+-="
Chr(34)&
Chr(9)&
Chr(32)
n=Len(s_BadStr)
IsSafeStr=True
Fori=1Ton
IfInstr(str,Mid(s_BadStr,i,1))>
0Then
IsSafeStr=False
50.
================================================
显示解释函数,返回根据参数允许显示的格式字符串,具体调用方法可从后台管理获得
输入参数:
s_Content:
要转换的数据字符串
s_Filters:
要过滤掉的格式集,用逗号分隔多个
Functionjimmycode(s_Content,sFilters)
D