ASP中常用的函數(shù)和詳細(xì)說明第1/2頁
更新時(shí)間:2007年03月02日 00:00:00 作者:
各位都把ASP用的函數(shù)和詳細(xì)說明貼出來,供大家學(xué)習(xí).
我知道的如下:
1.函數(shù)array()
功能:創(chuàng)建一個(gè)數(shù)組變量
格式:array(list)
參數(shù):list 為數(shù)組變量中的每個(gè)數(shù)值列,中間用逗號(hào)間隔
例子:
<% i = array ("1","2","3") %>
結(jié)果: i 被賦予為數(shù)組
2.函數(shù)Cint()
功能:將一表達(dá)式/其它類型的變量轉(zhuǎn)換成整數(shù)類型(int)
格式:Cint(expression)
參數(shù):expression 是任何有效的表達(dá)式/其它類型的變量
例子:
<%
f = "234"
response.write cINT(f) + 2
%>
結(jié)果: 236
函數(shù)Cint()將字符"234"轉(zhuǎn)換 成整數(shù)234.如果表達(dá)式為空, 或者無效時(shí),返回值為0;
3.函數(shù):Creatobject()
功能:創(chuàng)建及返回一個(gè)ActiveX對象.
格式:Creatobject(obname)
參數(shù)bname 是對象的名稱
例子:
<%
Set con = Server.CreateObject("ADODB.Connection")
%>
結(jié)果:
4.函數(shù)Cstr()
功能:將一表達(dá)式/其它類型的變量轉(zhuǎn)換成字符類型(string)
格式:Cstr(expression)
參數(shù):expression是任何有效的表達(dá)式/其它類型的變量
例子:
<%
s = 3 + 2
response.write "The result is:" & cStr(s)
%>
結(jié)果:函數(shù)Cstr()將整數(shù) 5 轉(zhuǎn)換 成字符"5".
5.函數(shù)Date()
功能:返回當(dāng)前系統(tǒng)(server端)的日期
格式: Date()
參數(shù):無
例子<% date () %>
結(jié)果:05/10/00
6.函數(shù)Dateadd()
功能:計(jì)算某個(gè)指定的時(shí)間和
格式: dateadd(timeinterval,number,date)
參數(shù):timeinterval是時(shí)間單位(月,日..); number是時(shí)間間隔值,date是時(shí)間始點(diǎn).
例子:
<%
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
%>
結(jié)果:
11/4/99
3:34:45 PM
其中
"m" = "month";
"d" = "day";
如果是currentDate 格式,則,
"h" = "hour";
"s" = "second";
7.函數(shù)Datediff()
功能:計(jì)算某量個(gè)指定的時(shí)間差
格式: datediff(timeinterval,date1,date2[,firstdayofweek[,firstdayofyear]])
參數(shù): timeinterval 是時(shí)間單位; date1,date2是有效的日期表達(dá)式,firstdayofweek,firstdayofyear 是任意選項(xiàng).
例子:
<%
fromDate = #8/4/99#
toDate = #1/1/2000#
response.write "There are " & _
DateDiff("d",fromDate,toDate) & _
" days to millenium from 8/4/99."
%>
結(jié)果:There are 150 days to millenium from 8/4/99.
8.函數(shù)day()
功能:返回一個(gè)整數(shù)值,對應(yīng)于某月的某日
格式: day(date)
參數(shù): date是一個(gè)有效的日期表達(dá)式;
例子<% =date(#8/4/99#) %>
結(jié)果:4
9.函數(shù)formatcurrency()
功能:轉(zhuǎn)換成貨幣格式
格式: formatcurrency(expression [,digit[,leadingdigit[,paren[,groupdigit]]]])
參數(shù): expression 是有效的數(shù)字表達(dá)式;digit表示小數(shù)點(diǎn)后的位數(shù);leadingdigit,paren,groupdigit是任意選項(xiàng).
例子<%=formatCurrency(34.3456)%>
結(jié)果34.35
10.函數(shù)formatdatetime()
功能:格式化日期表達(dá)式/變量
格式: formatdatetime(date[,nameformat])
參數(shù): date為有效的日期表達(dá)式/變量;nameformat是指定的日期格式常量名稱.
例子<% =formatdatetime("08/04/99",vblongdate) %>
結(jié)果:Wednesday,August 04,1999
說明:
-------------------------------------------------------------------<script language=vbs>
for i=0 to 4
alert(" formatdatetime(now,"&i&") 的時(shí)候是:"&formatdatetime(now,i))
next
</script>
-------------
描述
返回表達(dá)式,此表達(dá)式已被格式化為日期或時(shí)間?!?
語法
formatDateTime(Date[, Namedformat])
formatDateTime 函數(shù)的語法有以下參數(shù):
參數(shù) 描述
Date 必選項(xiàng)。要被格式化的日期表達(dá)式?!?
Namedformat 可選項(xiàng)。指示所使用的日期/時(shí)間格式的數(shù)值,如果省略,則使用 vbGeneralDate。
設(shè)置
Namedformat 參數(shù)可以有以下值:
常數(shù) 值 描述
vbGeneralDate 0 顯示日期和/或時(shí)間。如果有日期部分,則將該部分顯示為短日期格式。如果有時(shí)間部分,則將該部分顯示為長時(shí)間格式。如果都存在,則顯示所有部分?!?
vbLongDate 1 使用計(jì)算機(jī)區(qū)域設(shè)置中指定的長日期格式顯示日期。
vbShortDate 2 使用計(jì)算機(jī)區(qū)域設(shè)置中指定的短日期格式顯示日期?!?
vbLongTime 3 使用計(jì)算機(jī)區(qū)域設(shè)置中指定的時(shí)間格式顯示時(shí)間。
vbShortTime 4 使用 24 小時(shí)格式 (hh:mm) 顯示時(shí)間?!?
說明
下面例子利用 formatDateTime 函數(shù)把表達(dá)式格式化為長日期型并且把它賦給 MyDateTime:
Function GetCurrentDate
"formatDateTime 把日期型格式化為長日期型。
GetCurrentDate = formatDateTime(Date, 1)
End Function
--------------------------------------------------------------------------------
<script language=vbs>
for i=0 to 4
alert(" formatdatetime(now,"&i&") 的時(shí)候是:"&formatdatetime(now,i))
next
</script>
[Ctrl+A 全部選擇 提示:你可先修改部分代碼,再按運(yùn)行]
11.函數(shù)Isnumeric()
功能:返回一個(gè)布爾值,判斷變量是否為數(shù)字變量,或者是可以轉(zhuǎn)換成數(shù)字的其它變量.
格式:isnumeric(expression)
參數(shù):expression 是任意的變量.
例子:
<%
i="234"
response.write isnumeric(i)
%>
結(jié)果: true.
12.函數(shù)Isobject()
功能:返回一個(gè)布爾值,判斷變量是否為對象的變量,
格式: isobject(expression)
參數(shù): expression 是任意的變量.
例子:
<%
set con =server.creatobject("adodb.connection")
response.write isobject(con)
%>
結(jié)果: true
13.函數(shù):Lbound()
功能:返回一個(gè)數(shù)組的下界.
格式:Lbound(arrayname[,dimension])
參數(shù):arrayname 是數(shù)組變量,dimension 是任意項(xiàng)
例子:
<%
i = array("1","2","3")
response.write lbound(i)
%>
結(jié)果:0
14.函數(shù)Lcase()
功能:將一字符類型變量的字符全部變換小寫字符.
格式:Lcase(string)
參數(shù):string是字符串變量
例子:
<%
str="THIS is Lcase!"
response.write Lcase(str)
%>
結(jié)果:this is lcase!
15.函數(shù)left()
功能:截取一個(gè)字符串的前部分;
格式:left(string,length)
參數(shù):string字符串,length截取的長度.
例子: <% =left("this is a test!",6) %>
結(jié)果:this i
16.函數(shù)len()
功能:返回字符串長度或者變量的字節(jié)長度
格式:len(string *varname)
參數(shù):string字符串;varname任意的變量名稱
例子:
<%
strtest="this is a test!"
response.write len(strtest)
%>
結(jié)果:15
17.函數(shù)ltrim()
功能:去掉字符串前的空格.
格式:ltrim(string)
參數(shù):string 字符串.
例子: <% =ltrim (" this is a test!")
結(jié)果:this is a test!
18.函數(shù)Mid()
功能:從字符串中截取字符串.
格式:mid(string,start [,length])
參數(shù):string字符串,start截取的起點(diǎn),length要截取的長度.
例子:
<%
strtest="this is a test, Today is Monday!"
response.write mid(strtest,17,5)
%>
結(jié)果:Today
19.函數(shù)minute()
功能:返回一數(shù)值, 表示分鐘
格式:minute(time)
參數(shù): time是時(shí)間變量
例子lt;% =minute(#12:23:34#) %>
結(jié)果:23
我知道的如下:
1.函數(shù)array()
功能:創(chuàng)建一個(gè)數(shù)組變量
格式:array(list)
參數(shù):list 為數(shù)組變量中的每個(gè)數(shù)值列,中間用逗號(hào)間隔
例子:
<% i = array ("1","2","3") %>
結(jié)果: i 被賦予為數(shù)組
2.函數(shù)Cint()
功能:將一表達(dá)式/其它類型的變量轉(zhuǎn)換成整數(shù)類型(int)
格式:Cint(expression)
參數(shù):expression 是任何有效的表達(dá)式/其它類型的變量
例子:
<%
f = "234"
response.write cINT(f) + 2
%>
結(jié)果: 236
函數(shù)Cint()將字符"234"轉(zhuǎn)換 成整數(shù)234.如果表達(dá)式為空, 或者無效時(shí),返回值為0;
3.函數(shù):Creatobject()
功能:創(chuàng)建及返回一個(gè)ActiveX對象.
格式:Creatobject(obname)
參數(shù)bname 是對象的名稱
例子:
<%
Set con = Server.CreateObject("ADODB.Connection")
%>
結(jié)果:
4.函數(shù)Cstr()
功能:將一表達(dá)式/其它類型的變量轉(zhuǎn)換成字符類型(string)
格式:Cstr(expression)
參數(shù):expression是任何有效的表達(dá)式/其它類型的變量
例子:
<%
s = 3 + 2
response.write "The result is:" & cStr(s)
%>
結(jié)果:函數(shù)Cstr()將整數(shù) 5 轉(zhuǎn)換 成字符"5".
5.函數(shù)Date()
功能:返回當(dāng)前系統(tǒng)(server端)的日期
格式: Date()
參數(shù):無
例子<% date () %>
結(jié)果:05/10/00
6.函數(shù)Dateadd()
功能:計(jì)算某個(gè)指定的時(shí)間和
格式: dateadd(timeinterval,number,date)
參數(shù):timeinterval是時(shí)間單位(月,日..); number是時(shí)間間隔值,date是時(shí)間始點(diǎn).
例子:
<%
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
%>
結(jié)果:
11/4/99
3:34:45 PM
其中
"m" = "month";
"d" = "day";
如果是currentDate 格式,則,
"h" = "hour";
"s" = "second";
7.函數(shù)Datediff()
功能:計(jì)算某量個(gè)指定的時(shí)間差
格式: datediff(timeinterval,date1,date2[,firstdayofweek[,firstdayofyear]])
參數(shù): timeinterval 是時(shí)間單位; date1,date2是有效的日期表達(dá)式,firstdayofweek,firstdayofyear 是任意選項(xiàng).
例子:
<%
fromDate = #8/4/99#
toDate = #1/1/2000#
response.write "There are " & _
DateDiff("d",fromDate,toDate) & _
" days to millenium from 8/4/99."
%>
結(jié)果:There are 150 days to millenium from 8/4/99.
8.函數(shù)day()
功能:返回一個(gè)整數(shù)值,對應(yīng)于某月的某日
格式: day(date)
參數(shù): date是一個(gè)有效的日期表達(dá)式;
例子<% =date(#8/4/99#) %>
結(jié)果:4
9.函數(shù)formatcurrency()
功能:轉(zhuǎn)換成貨幣格式
格式: formatcurrency(expression [,digit[,leadingdigit[,paren[,groupdigit]]]])
參數(shù): expression 是有效的數(shù)字表達(dá)式;digit表示小數(shù)點(diǎn)后的位數(shù);leadingdigit,paren,groupdigit是任意選項(xiàng).
例子<%=formatCurrency(34.3456)%>
結(jié)果34.35
10.函數(shù)formatdatetime()
功能:格式化日期表達(dá)式/變量
格式: formatdatetime(date[,nameformat])
參數(shù): date為有效的日期表達(dá)式/變量;nameformat是指定的日期格式常量名稱.
例子<% =formatdatetime("08/04/99",vblongdate) %>
結(jié)果:Wednesday,August 04,1999
說明:
-------------------------------------------------------------------<script language=vbs>
for i=0 to 4
alert(" formatdatetime(now,"&i&") 的時(shí)候是:"&formatdatetime(now,i))
next
</script>
-------------
描述
返回表達(dá)式,此表達(dá)式已被格式化為日期或時(shí)間?!?
語法
formatDateTime(Date[, Namedformat])
formatDateTime 函數(shù)的語法有以下參數(shù):
參數(shù) 描述
Date 必選項(xiàng)。要被格式化的日期表達(dá)式?!?
Namedformat 可選項(xiàng)。指示所使用的日期/時(shí)間格式的數(shù)值,如果省略,則使用 vbGeneralDate。
設(shè)置
Namedformat 參數(shù)可以有以下值:
常數(shù) 值 描述
vbGeneralDate 0 顯示日期和/或時(shí)間。如果有日期部分,則將該部分顯示為短日期格式。如果有時(shí)間部分,則將該部分顯示為長時(shí)間格式。如果都存在,則顯示所有部分?!?
vbLongDate 1 使用計(jì)算機(jī)區(qū)域設(shè)置中指定的長日期格式顯示日期。
vbShortDate 2 使用計(jì)算機(jī)區(qū)域設(shè)置中指定的短日期格式顯示日期?!?
vbLongTime 3 使用計(jì)算機(jī)區(qū)域設(shè)置中指定的時(shí)間格式顯示時(shí)間。
vbShortTime 4 使用 24 小時(shí)格式 (hh:mm) 顯示時(shí)間?!?
說明
下面例子利用 formatDateTime 函數(shù)把表達(dá)式格式化為長日期型并且把它賦給 MyDateTime:
Function GetCurrentDate
"formatDateTime 把日期型格式化為長日期型。
GetCurrentDate = formatDateTime(Date, 1)
End Function
--------------------------------------------------------------------------------
<script language=vbs>
for i=0 to 4
alert(" formatdatetime(now,"&i&") 的時(shí)候是:"&formatdatetime(now,i))
next
</script>
[Ctrl+A 全部選擇 提示:你可先修改部分代碼,再按運(yùn)行]
11.函數(shù)Isnumeric()
功能:返回一個(gè)布爾值,判斷變量是否為數(shù)字變量,或者是可以轉(zhuǎn)換成數(shù)字的其它變量.
格式:isnumeric(expression)
參數(shù):expression 是任意的變量.
例子:
<%
i="234"
response.write isnumeric(i)
%>
結(jié)果: true.
12.函數(shù)Isobject()
功能:返回一個(gè)布爾值,判斷變量是否為對象的變量,
格式: isobject(expression)
參數(shù): expression 是任意的變量.
例子:
<%
set con =server.creatobject("adodb.connection")
response.write isobject(con)
%>
結(jié)果: true
13.函數(shù):Lbound()
功能:返回一個(gè)數(shù)組的下界.
格式:Lbound(arrayname[,dimension])
參數(shù):arrayname 是數(shù)組變量,dimension 是任意項(xiàng)
例子:
<%
i = array("1","2","3")
response.write lbound(i)
%>
結(jié)果:0
14.函數(shù)Lcase()
功能:將一字符類型變量的字符全部變換小寫字符.
格式:Lcase(string)
參數(shù):string是字符串變量
例子:
<%
str="THIS is Lcase!"
response.write Lcase(str)
%>
結(jié)果:this is lcase!
15.函數(shù)left()
功能:截取一個(gè)字符串的前部分;
格式:left(string,length)
參數(shù):string字符串,length截取的長度.
例子: <% =left("this is a test!",6) %>
結(jié)果:this i
16.函數(shù)len()
功能:返回字符串長度或者變量的字節(jié)長度
格式:len(string *varname)
參數(shù):string字符串;varname任意的變量名稱
例子:
<%
strtest="this is a test!"
response.write len(strtest)
%>
結(jié)果:15
17.函數(shù)ltrim()
功能:去掉字符串前的空格.
格式:ltrim(string)
參數(shù):string 字符串.
例子: <% =ltrim (" this is a test!")
結(jié)果:this is a test!
18.函數(shù)Mid()
功能:從字符串中截取字符串.
格式:mid(string,start [,length])
參數(shù):string字符串,start截取的起點(diǎn),length要截取的長度.
例子:
<%
strtest="this is a test, Today is Monday!"
response.write mid(strtest,17,5)
%>
結(jié)果:Today
19.函數(shù)minute()
功能:返回一數(shù)值, 表示分鐘
格式:minute(time)
參數(shù): time是時(shí)間變量
例子lt;% =minute(#12:23:34#) %>
結(jié)果:23
相關(guān)文章
用ASP開發(fā)網(wǎng)頁需要牢記的注意事項(xiàng)
ASP開發(fā)網(wǎng)頁需要牢記的注意事項(xiàng),使用asp的朋友可以看看2006-06-06ServerVariables集合檢索預(yù)定的環(huán)境變量
ServerVariables集合檢索預(yù)定的環(huán)境變量...2007-02-02