ASP中的函数说明[1]

[入库:2005年8月18日] [更新:2007年3月25日]

本文简介:选择自 asthlon 的 blog

array()
 function:返回一个数组
 syntax:array(list)
 arguments:字符,数字均可
 example:<%
dim myarray()
for i = 1 to 7
 redim preserve myarray(i)
 myarray(i) = weekdayname(i)
next
%>
 result:建立了一个包含7个元素的数组myarray
myarray("sunday","monday", ... ... "saturday")

cint()
 function:将一个表达式转化为数字类型
 syntax:cint(expression)
 arguments:任何有效的字符均可
 example:<%
f = "234"
response.write cint(f) + 2
%>
 result:236
转化字符"234"为数字"234",如果字符串为空,则返回0值

createobject()
 function:建立和返回一个已注册的activex组件的实例。
 syntax:createobject(objname)
 arguments:objname 是任何一个有效、已注册的activex组件的名字.
 example:<%
set con = server.createobject("adodb.connection")
%>
 result:

cstr()
 function:转化一个表达式为字符串.
 syntax:cstr(expression)
 arguments:expression 是任何有效的表达式。
 example:<%
s = 3 + 2
response.write "the result is: " & cstr(s)
%>
 result:转化数字“5”为字符“5”。

date()
 function:返回当前系统日期.
 syntax:date()
 arguments:none.
 example:<%=date%>
 result:8/4/99

dateadd()
 function:返回一个被改变了的日期。
 syntax:dateadd(timeinterval,number,date)
 arguments:timeinterval is the time interval to add; number is amount of time intervals to add; and date is the starting date.
 example:<%
currentdate = #8/4/99#
newdate = dateadd("m",3,currentdate)
response.write newdate
%>

<%
currentdate = #12:34:45 pm#
newdate = dateadd("h",3,currentdate)
response.write newdate
%>
 result:11/4/99
3:34:45 pm

"m" = "month";
"d" = "day";

if currentdate is in time format then,
"h" = "hour";
"s" = "second";

datediff()
 function:返回两个日期之间的差值 。
 syntax:datediff(timeinterval,date1,date2 [, firstdayofweek [, firstweekofyear]])
 arguments:timeinterval 表示相隔时间的类型,如“m“表示“月”。
 example:<%
fromdate = #8/4/99#
todate = #1/1/2000#
response.write "there are " & _
 datediff("d",fromdate,todate) & _
 " days to millenium from 8/4/99."
%>
 result:从8/4/99 到2000年还有 150 天.

day()
 function:返回一个月的第几日.
 syntax:day(date)
 arguments:date 是任何有效的日期。
 example:<%=day(#8/4/99#)%>
 result:4

formatcurrency()
 function:返回表达式,此表达式已被格式化为货币值
 syntax:formatcurrency(expression [, digit [, leadingdigit [, paren [, groupdigit]]]])
 arguments: digit 指示小数点右侧显示位数的数值。默认值为 -1,指示使用的是计算机的区域设置; leadingdigit 三态常数,指示是否显示小数值小数点前面的零。
 example:<%=formatcurrency(34.3456)%>
 result:$34.35

formatdatetime()
 function:返回表达式,此表达式已被格式化为日期或时间
 syntax:formatdatetime(date, [, namedformat])
 arguments:namedformat 指示所使用的日期/时间格式的数值,如果省略,则使用 vbgeneraldate.
 example:<%=formatdatetime("08/4/99", vblongdate)%>
 result:wednesday, august 04, 1999

formatnumber()
 function:返回表达式,此表达式已被格式化为数值.
 syntax:formatnumber(expression [, digit [, leadingdigit [, paren [, groupdigit]]]])
 arguments: digit 指示小数点右侧显示位数的数值。默认值为 -1,指示使用的是计算机的区域设置。; leadingdigit i指示小数点右侧显示位数的数值。默认值为 -1,指示使用的是计算机的区域设置。; paren 指示小数点右侧显示位数的数值。默认值为 -1,指示使用的是计算机的区域设置。; groupdigit i指示小数点右侧显示位数的数值。默认值为 -1,指示使用的是计算机的区域设置。.
 example:<%=formatnumber(45.324567, 3)%>
 result:45.325

formatpercent()
 function:返回表达式,此表达式已被格式化为尾随有 % 符号的百分比(乘以 100 )。 (%)
 syntax:formatpercent(expression [, digit [, leadingdigit [, paren [, groupdigit]]]])
 arguments:同上.
 example:<%=formatpercent(0.45267, 3)%>
 result:45.267%

hour()
 function:以24时返回小时数.
 syntax:hour(time)
 arguments:
 example:<%=hour(#4:45:34 pm#)%>
 result:16
(hour has been converted to 24-hour system)

instr()
 function:返回字符或字符串在另一个字符串中第一次出现的位置.
 syntax:instr([start, ] strtobesearched, strsearchfor [, compare])
 arguments:start为搜索的起始值,strtobesearched接受搜索的字符串strsearchfor要搜索的字符.compare比较方式(详细见asp常数)
 example:<%
strtext = "this is a test!!"
pos = instr(strtext, "a")
response.write pos
%>
 result:9

instrrev()
 function:同上,只是从字符串的最后一个搜索起
 syntax:instrrev([start, ] strtobesearched, strsearchfor [, compare])
 arguments:同上.
 example:<%
strtext = "this is a test!!"
pos = instrrev(strtext, "s")
response.write pos
%>
 result:13


int()
 function:返回数值类型,不四舍五入。
 syntax:int(number)
 arguments:
 example:<%=int(32.89)%>
 result:32

isarray()
 function:判断一对象是否为数组,返回布尔值.
 syntax:isarray(name)
 arguments:
 example:<%
strtest = "test!"
response.write isarray(strtest)
%>
 result:false

isdate()

本文关键:ASP中的函数说明
 

本站最佳浏览方式为 分辨率 1024x768 IE 6.0(或更高版本的 IE浏览器)

go top