ASP函數(shù)大全2008-09-03 20:59:01 來源:互聯(lián)網(wǎng) 作者:編輯整理
這里轉(zhuǎn)載了asp函數(shù)
語法
CLng(expression)
expression 參數(shù)是任意有效的表達(dá)式。
描述
返回表達(dá)式,此表達(dá)式已被轉(zhuǎn)換為 Long 子類型的 Variant。
說明
通常,您可以使用子類型數(shù)據(jù)轉(zhuǎn)換函數(shù)書寫代碼,以顯示某些操作的結(jié)果應(yīng)當(dāng)被表達(dá)為特定的數(shù)據(jù)類型,而非默認(rèn)的數(shù)據(jù)類型。例如,在出現(xiàn)貨幣運算、單精度或雙精度算術(shù)運算的情況下,使用 CInt 或 CLng 函數(shù)強制進(jìn)行整數(shù)運算。
CLng 函數(shù)用于進(jìn)行從其他數(shù)據(jù)類型到 Long 子類型的的國際公認(rèn)的格式轉(zhuǎn)換。例如,對十進(jìn)制分隔符和千位分隔符的識別取決于系統(tǒng)的區(qū)域設(shè)置。
如果 expression 取值不在 Long 子類型的允許范圍內(nèi),則會出現(xiàn)錯誤。
--------------------------------------------------------------------------------
注意 CLng 函數(shù)與 Fix 和 Int 函數(shù)功能不同,后兩者函數(shù)對數(shù)值的小數(shù)部分進(jìn)行截尾取整而不是四舍五入。當(dāng)小數(shù)部分恰好等于 0.5 時, CLng 函數(shù)通常向與此數(shù)最接近的偶數(shù)取整。例如,0.5 取整為 0、1.5 取整為 2。
Array()
函數(shù)返回一個數(shù)組
表達(dá)式 Array(list)
允許數(shù)據(jù)類型: 字符,數(shù)字均可
實例:
<%
Dim myArray()
For i = 1 to 7
Redim Preserve myArray(i)
myArray(i) = WeekdayName(i)
Next
%>
返回結(jié)果: 建立了一個包含7個元素的數(shù)組myArray
myArray("Sunday","Monday", ... ... "Saturday")
CInt()
函數(shù)將一個表達(dá)式轉(zhuǎn)化為數(shù)字類型
表達(dá)式 CInt(expression)
允許數(shù)據(jù)類型: 任何有效的字符均可
實例:
<%
f = "234"
response.write cINT(f) + 2
%>
返回結(jié)果: 236
轉(zhuǎn)化字符"234"為數(shù)字"234",如果字符串為空,則返回0值
CreateObject()
函數(shù)建立和返回一個已注冊的ACTIVEX組件的實例。
表達(dá)式 CreateObject(objName)
允許數(shù)據(jù)類型: objName 是任何一個有效、已注冊的ACTIVEX組件的名字.
實例: <%
Set con = Server.CreateObject("ADODB.Connection")
%>
CStr()
函數(shù)轉(zhuǎn)化一個表達(dá)式為字符串.
表達(dá)式 CStr(expression)
允許數(shù)據(jù)類型: expression 是任何有效的表達(dá)式。
實例: <%
s = 3 + 2
response.write "The 返回結(jié)果 is: " & cStr(s)
%>
返回結(jié)果: 轉(zhuǎn)化數(shù)字“5”為字符“5”。
Date()
函數(shù)返回當(dāng)前系統(tǒng)日期.
表達(dá)式 Date()
允許數(shù)據(jù)類型: None.
實例: <%=Date%>
返回結(jié)果: 9/9/00
DateAdd()
函數(shù)返回一個被改變了的日期。
表達(dá)式 DateAdd(timeinterval,number,date)
允許數(shù)據(jù)類型:
timeinterval is the time interval to add;
number is amount of time intervals to add;
and date is the starting date.
實例: <%
currentDate = #9/9/00#
newDate = DateAdd("m",3,currentDate)
response.write newDate
%>
<%
currentDate = #12:34:45 PM#
newDate = DateAdd("h",3,currentDate)
response.write newDate
%>
返回結(jié)果: 9/9/00
3:34:45 PM
"m" = "month";
"d" = "day";
If currentDate is in time format then,
"h" = "hour";
"s" = "second";
DateDiff()
函數(shù)返回兩個日期之間的差值 。
表達(dá)式 DateDiff(timeinterval,date1,date2 [, firstdayofweek [, firstweekofyear]])
允許數(shù)據(jù)類型: timeinterval 表示相隔時間的類型,如“M“表示“月”。
實例: <%
fromDate = #9/9/00#
toDate = #1/1/2000#
response.write "There are " & _
DateDiff("d",fromDate,toDate) & _
" days to millenium from 9/9/00."
%>
返回結(jié)果: 從9/9/00 到2000年還有 150 天.
Day()
函數(shù)返回一個月的第幾日 .
表達(dá)式 Day(date)
允許數(shù)據(jù)類型: date 是任何有效的日期。
實例: <%=Day(#9/9/00#)%>
返回結(jié)果: 4
FormatCurrency()
函數(shù)返回表達(dá)式,此表達(dá)式已被格式化為貨幣值
表達(dá)式 FormatCurrency(Expression [, Digit [, LeadingDigit [, Paren [, GroupDigit]]]])
允許數(shù)據(jù)類型: Digit 指示小數(shù)點右側(cè)顯示位數(shù)的數(shù)值。默認(rèn)值為 -1,指示使用的是計算機的區(qū)域設(shè)置; LeadingDigit 三態(tài)常數(shù),指示是否顯示小數(shù)值小數(shù)點前面的零。
實例: <%=FormatCurrency(34.3456)%>
返回結(jié)果: $34.35
FormatDateTime()
函數(shù)返回表達(dá)式,此表達(dá)式已被格式化為日期或時間
表達(dá)式 FormatDateTime(Date, [, NamedFormat])
允許數(shù)據(jù)類型: NamedFormat 指示所使用的日期/時間格式的數(shù)值,如果省略,則使用 vbGeneralDate.
實例: <%=FormatDateTime("09/9/00", vbLongDate)%>
返回結(jié)果: Sunday, September 09, 2000
FormatNumber()
函數(shù)返回表達(dá)式,此表達(dá)式已被格式化為數(shù)值.
表達(dá)式 FormatNumber(Expression [, Digit [, LeadingDigit [, Paren [, GroupDigit]]]])
允許數(shù)據(jù)類型: Digit 指示小數(shù)點右側(cè)顯示位數(shù)的數(shù)值。默認(rèn)值為 -1,指示使用的是計算機的區(qū)域設(shè)置。; LeadingDigit i指示小數(shù)點右側(cè)顯示位數(shù)的數(shù)值。默認(rèn)值為 -1,指示使用的是計算機的區(qū)域設(shè)置。; Paren 指示小數(shù)點右側(cè)顯示位數(shù)的數(shù)值。默認(rèn)值為 -1,指示使用的是計算機的區(qū)域設(shè)置。; GroupDigit i指示小數(shù)點右側(cè)顯示位數(shù)的數(shù)值。默認(rèn)值為 -1,指示使用的是計算機的區(qū)域設(shè)置。.
實例: <%=FormatNumber(45.324567, 3)%>
返回結(jié)果: 45.325
FormatPercent()
函數(shù)返回表達(dá)式,此表達(dá)式已被格式化為尾隨有 % 符號的百分比(乘以 100 )。 (%)
表達(dá)式 FormatPercent(Expression [, Digit [, LeadingDigit [, Paren [, GroupDigit]]]])
允許數(shù)據(jù)類型: 同上.
實例: <%=FormatPercent(0.45267, 3)%>
返回結(jié)果: 45.267%
Hour()
函數(shù)以24時返回小時數(shù).
表達(dá)式 Hour(time)
允許數(shù)據(jù)類型:
實例: <%=Hour(#4:45:34 PM#)%>
返回結(jié)果: 16
(Hour has been converted to 24-hour system)
Instr()
函數(shù)返回字符或字符串在另一個字符串中第一次出現(xiàn)的位置.
表達(dá)式 Instr([start, ] strToBeSearched, strSearchFor [, compare])
允許數(shù)據(jù)類型: Start為搜索的起始值,strToBeSearched接受搜索的字符串 strSearchFor要搜索的字符.compare比較方式(詳細(xì)見ASP常數(shù))
實例: <%
strText = "This is a test!!"
pos = Instr(strText, "a")
response.write pos
%>
返回結(jié)果: 9
InstrRev()
函數(shù)同上,只是從字符串的最后一個搜索起
表達(dá)式 InstrRev([start, ] strToBeSearched, strSearchFor [, compare])
允許數(shù)據(jù)類型: 同上.
實例: <%
strText = "This is a test!!"
pos = InstrRev(strText, "s")
response.write pos
%>
返回結(jié)果: 13
Int()
函數(shù)返回數(shù)值類型,不四舍五入。
表達(dá)式 Int(number)
允許數(shù)據(jù)類型:
實例: <%=INT(32.89)%>
返回結(jié)果: 32
IsArray()
函數(shù)判斷一對象是否為數(shù)組,返回布爾值 .
表達(dá)式 IsArray(name)
實例: <%
strTest = "Test!"
response.write IsArray(strTest)
%>
返回結(jié)果: False
IsDate()
函數(shù)判斷一對象是否為日期,返回布爾值
表達(dá)式 IsDate(expression)
實例: <%
strTest = "9/4/2000"
response.write IsDate(strTest)
%>
返回結(jié)果: True
IsEmpty()
函數(shù)判斷一對象是否初始化,返回布爾值.
表達(dá)式 IsEmpty(expression)
實例: <%
Dim i
response.write IsEmpty(i)
%>
返回結(jié)果: True
IsNull()
函數(shù)判斷一對象是否為空,返回布爾值.
表達(dá)式 IsNull(expression)
實例: <%
Dim i
response.write IsNull(i)
%>
返回結(jié)果: False
IsNumeric()
函數(shù)判斷一對象是否為數(shù)字,返回布爾值.
表達(dá)式 IsNumeric(expression)
實例: <%
i = "345"
response.write IsNumeric(i)
%>
返回結(jié)果: True
就算數(shù)字加了引號,ASP還是認(rèn)為它是數(shù)字。
IsObject()
函數(shù)判斷一對象是否為對象,返回布爾值.
表達(dá)式 IsObject(expression)
實例: <%
Set con = Server.CreateObject("ADODB.Connection")
response.write IsObject(con)
%>
返回結(jié)果: True
LBound()
函數(shù)返回指定數(shù)組維的最小可用下標(biāo).
表達(dá)式 Lbound(arrayname [, dimension])
實例: <%
i = Array("Monday","Tuesday","Wednesday")
response.write LBound(i)
%>
返回結(jié)果: 0
LCase()
函數(shù) 返回字符串的小寫形式
表達(dá)式 Lcase(string)
實例: <%
strTest = "This is a test!"
response.write LCase(strTest)
%>
返回結(jié)果: this is a test!
Left()
函數(shù)返回字符串左邊第length個字符以前的字符(含第length個字符).
表達(dá)式 Left(string, length)
實例: <%
strTest = "This is a test!"
response.write Left(strTest, 3)
%>
返回結(jié)果: Thi
Len()
函數(shù)返回字符串的長度.
表達(dá)式 Len(string | varName)
實例: <%
strTest = "This is a test!"
response.write Len(strTest)
%>
返回結(jié)果: 15
LTrim()
函數(shù)去掉字符串左邊的空格.
表達(dá)式 LTrim(string)
實例: <%
strTest = " This is a test!"
response.write LTrim(strTest)
%>
返回結(jié)果: This is a test!
Mid()
函數(shù)返回特定長度的字符串(從start開始,長度為length).
表達(dá)式 Mid(string, start [, length])
實例: <%
strTest = "This is a test! Today is Monday."
response.write Mid(strTest, 17, 5)
%>
返回結(jié)果: Today