通過實例講解來學習ASP中的函數_ASP教程
推薦:ASP中Session技巧寫過稍微大型一點 ASP 的人都知道,Session 這個對象真是好用,它可以用來記錄使用者私有的資料變量,既安全又方便。但是你真的知道 session 的運作原理嗎?或許了解以后,你就再也不太敢使用這
作用:返回一個數組
語法:Array(list)
適用的類型:字符,數字均可
以下為引用的內容: <% Dim myArray() For i = 1 to 7 Redim Preserve myArray(i) myArray(i) = WeekdayName(i) Next %> |
結果:建立了一個包含7個元素的數組myArray
myArray("Sunday","Monday", ... ... "Saturday")
CInt()
作用:將一個表達式轉化為數字類型
語法:CInt(表達式)
適用的類型:任何有效的字符均可
以下為引用的內容: <% f = "234" response.write cINT(f) 2 %> |
結果:236
轉化字符"234"為數字234,如果字符串為空,則返回0值
CreateObject()
作用:建立和返回一個已注冊的ACTIVEX組件的實例。
語法:CreateObject(objName)
適用的類型: objName 是任何一個有效、已注冊的ACTIVEX組件的名字。
以下為引用的內容: <% Set con = Server.CreateObject("ADODB.Connection") %> CStr() |
作用:轉化一個表達式為字符串。
語法:CStr(expression)
適用類型:expression 是任何有效的表達式
以下為引用的內容: <% s = 3 2 response.write("The 結果 is: " & cStr(s)) %> |
結果: 轉化數字5為字符“5”。
Date()
作用:返回當前系統日期。
語法:Date()
適用的類型:None。
<%=Date%>
結果:8/4/99
DateAdd()
作用:返回一個被改變了的日期。
語法:DateAdd(timeinterval,number,date)
說明:timeinterval為所要加入的時間間隔類型;number為要添加的數量;date為起始日期.
以下為引用的內容: <% <% 結果:11/4/99 3:34:45 PM "m" = "month"; 當當前日期格式為time,那么 "h" = "hour"; DateDiff() |
作用:返回兩個日期之間的差值。
語法:DateDiff(timeinterval,date1,date2 [, firstdayofweek [, firstweekofyear >>)
說明:timeinterval 表示相隔時間的類型,如“M“表示“月”。
以下為引用的內容: <% fromDate = #8/4/99# toDate = #1/1/2000# response.write("There are " & _ DateDiff("d",fromDate,toDate) & _ " days to millenium from 8/4/99." %> |
結果:There are150daysto millenium from 8/4/99
Day()
作用:返回一個月的第幾日。
語法:Day(date)
說明:date 是任何有效的日期。
<%=Day(#8/4/99#)%>
結果:4
FormatCurrency()
作用:返回表達式,此表達式已被格式化為貨幣值
語法:FormatCurrency(Expression [, Digit [, LeadingDigit [, Paren [, GroupDigit >>>>)
說明:Digit 指示小數點右側顯示位數的數值。默認值為 -1,指示使用的是計算機的區域設置;LeadingDigit 三態常數,指示是否顯示小數值小數點前面的零
<%=FormatCurrency(34.3456)%>
結果:$34.35
FormatDateTime()
作用:返回表達式,此表達式已被格式化為日期或時間
語法:FormatDateTime(Date, [, NamedFormat >)
說明:NamedFormat 指示所使用的日期/時間格式的數值,如果省略,則使用 vbGeneralDate.
<%=FormatDateTime("08/4/99", vbLongDate)%>
結果:Wednesday, August 04, 1999
FormatNumber()
作用:返回表達式,此表達式已被格式化為數值
語法:FormatNumber(Expression [, Digit [, LeadingDigit [, Paren [, GroupDigit >>>>)
說明:Digit 指示小數點右側顯示位數的數值。默認值為 -1,指示使用的是計算機的區域設置。; LeadingDigit i指示小數點右側顯示位數的
數值。默認值為 -1,指示使用的是計算機的區域設置。; Paren 指示小數點右側顯示位數的數值。默認值為 -1,指示使用的是計算機的區域
設置。; GroupDigit i指示小數點右側顯示位數的數值。默認值為 -1,指示使用的是計算機的區域設置
<%=FormatNumber(45.324567, 3)%>
結果: 45.325
FormatPercent()
作用:返回表達式,此表達式已被格式化為尾隨有 % 符號的百分比(乘以 100 )。 (%)
語法:FormatPercent(Expression [, Digit [, LeadingDigit [, Paren [, GroupDigit >>>>)
說明:同上
<%=FormatPercent(0.45267, 3)%>
結果: 45.267%
Hour()
作用:以24時返回小時數
語法:Hour(time)
說明:
<%=Hour(#4:45:34 PM#)%>
結果:16
Instr()
作用:返回字符或字符串在另一個字符串中第一次出現的位置.
語法:Instr([start, > strToBeSearched, strSearchFor [, compare>)
說明:Start為搜索的起始值,strToBeSearched接受搜索的字符串 strSearchFor要搜索的字符compare 比較方式(詳細見ASP常數)
以下為引用的內容: <% strText = "This is a test!!" pos = Instr(strText, "a") response.write pos %> |
結果:9
InstrRev()
作用:同上,只是從字符串的最后一個搜索起
語法:InstrRev([start, > strToBeSearched, strSearchFor [, compare>)
說明:同上.
以下為引用的內容: <% strText = "This is a test!!" pos = InstrRev(strText, "s") response.write pos %> |
結果:13
Int()
作用:返回數值類型,不四舍五入。
語法:Int(number)
說明:
<%=INT(32.89)%>
結果:32
IsArray()
作用:判斷一對象是否為數組,返回布爾值.
語法:IsArray(name)
說明:
以下為引用的內容: <% strTest = "Test!" response.write IsArray(strTest) %> |
結果:False
IsDate()
作用:判斷一對象是否為日期,返回布爾值語法: IsDate(expression) 說明: expression is any valid expression.
以下為引用的內容: <% strTest = "8/4/99" response.write IsDate(strTest) %> |
結果:True
IsEmpty()
作用:判斷一對象是否初始化,返回布爾值.
語法:IsEmpty(expression)
說明:
以下為引用的內容: <% Dim i response.write IsEmpty(i) %> |
結果:True
IsNull()
作用:判斷一對象是否為空,返回布爾值.
語法:IsNull(expression)
說明:
以下為引用的內容: <% Dim i response.write IsNull(i) %> |
結果:False
IsNumeric()
作用:判斷一對象是否為數字,返回布爾值.
語法:IsNumeric(expression)
說明:
以下為引用的內容: <% i = "345" response.write IsNumeric(i) %> |
結果:True
就算數字加了引號,ASP還是認為它是數字。
IsObject()
作用:判斷一對象是否為對象,返回布爾值.
語法:IsObject(expression)
說明:
以下為引用的內容: <% Set con = Server.CreateObject( "ADODB.Connection") response.write IsObject(con) %> |
結果:True
LBound()
作用:返回指定數組維的最小可用下標.
語法:Lbound(arrayname [, dimension >)
說明:dimension 指明要返回哪一維下界的整數。使用1表示第一維,2表示第二維,以此類推。如果省略 dimension 參數,默認值為 1.
以下為引用的內容: <% i = Array( "Monday","Tuesday","Wednesday") response.write LBound(i) %> |
結果:0
LCase()
作用:返回字符串的小寫形式
語法:Lcase(string)
說明:string is any valid string expression.
以下為引用的內容: <% strTest = "This is a test!" response.write LCase(strTest) %> |
結果:this is a test!
Left()
作用:返回字符串左邊第length個字符以前的字符(含第length個字符).
語法:Left(string, length)
說明:
以下為引用的內容: <% strTest = "This is a test!" response.write Left(strTest, 3) %> |
結果:Thi
Len()
作用:返回字符串的長度.
語法:Len(string | varName)
說明:
以下為引用的內容: <% strTest = "This is a test!" response.write Len(strTest) %> |
結果:15
LTrim()
作用:去掉字符串左邊的空格.
語法:LTrim(string)
說明:
以下為引用的內容: <% strTest = " This is a test!" response.write LTrim(strTest) %> |
結果:This is a test!
Mid()
作用:返回特定長度的字符串(從start開始,長度為length).
語法:Mid(string, start [, length >)
說明:
以下為引用的內容: <% strTest = "This is a test! Today is Monday." response.write Mid(strTest, 17, 5) %> |
結果:Today
Minute()
作用:返回時間的分釧.
語法:Minute(time)
說明:
<%=Minute(#12:45:32 PM#)%>
結果:45
Month()
作用:返回日期.
語法:Month(date)
說明:date is any valid date expression.
<%=Month(#08/04/99#)%>
結果:8
MonthName()
作用:Returns a string identifying the specified month.
語法:MonthName(month, [, Abb >)
說明:month is the numeric representation for a given month; Abb (optional) is a boolean value used to display month abbreviation. True will display the abbreviated month name and False (default) will not show the abbreviation.
<%=MonthName(Month(#08/04/99#))%>
結果:August
Now()
作用:Returns the current system date and time.返回當前系統時間
語法:Now()
說明:None
<%=Now%>
結果:8/4/99 9:30:16 AM
Replace()
作用:Returns a string in which a specified sub-string has been replaced with another substring a specified number of times.
語法:Replace(strToBeSearched, strSearchFor, strReplaceWith [, start [, count [, compare >>>)
以下為引用的內容: 說明:strToBeSearched is a string expression containing a sub-string to be replaced; strSearchFor is the string expression to search for within strToBeSearched; strReplaceWith is the string expression to replace sub-string strSearchFor; start (optional) is the numeric character position to begin search; count (optional) is a value indicating the comparision constant. <% strTest = "This is an apple!" response.write Replace(strTest, "apple", "orange") %> |
結果:This is an orange!
Right()
作用:返回字符串右邊第length個字符以前的字符(含第length個字符).
語法:Right(string, length)
說明:
以下為引用的內容: <% strTest = "This is an test!" response.write Right(strTest, 3) %> |
結果:st!
Rnd()
作用:產生一個隨機數.
語法:Rnd [ (number) >
說明:
以下為引用的內容: <% Randomize() response.write RND() %> |
結果:任何一個在0 到 1 之間的數
Round()
作用:返回按指定位數進行四舍五入的數值.
語法:Round(expression [, numRight >)
說明:numRight數字表明小數點右邊有多少位進行四舍五入。如果省略,則 Round 函數返回整數.
以下為引用的內容: <% i = 32.45678 response.write Round(i) %> |
結果:32
Rtrim()
作用:去掉字符串右邊的空格字符串.
語法:Rtrim(string)
說明:
以下為引用的內容: <% strTest = "This is a test!! " response.write RTrim(strTest) %> |
結果:This is a test!!
Second()
作用:返回秒.
語法:Second(time)
說明:
<%=Second(#12:34:28 PM#)%>
結果:28
StrReverse()
作用:反排一字符串
語法:StrReverse(string)
說明
以下為引用的內容: <% strTest = "This is a test!!" response.write StrReverse(strTest) %> |
結果:!!tset a si sihT
Time()
作用:返回系統時間.
語法:Time()
說明:
<%=Time%>
結果:9:58:28 AM
Trim()
作用:去掉字符串左右的空格.
語法:Trim(string)
說明:string is any valid string expression.
以下為引用的內容: <% strTest = " This is a test!! " response.write Trim(strTest) %> |
結果:This is a test!!
UBound()
作用:返回指定數組維數的最大可用下標.
語法:Ubound(arrayname [, dimension >)
說明:dimension (optional) 指定返回哪一維上界的整數。1 表示第一維,2 表示第二維,以此類推。如果省略 dimension 參數,則默認值為 1.
以下為引用的內容: <% i = Array( "Monday","Tuesday","Wednesday") response.write UBound(i) %> |
結果:2
UCase()
作用:返回字符串的大寫形式.
語法:UCase(string)
說明:
以下為引用的內容: <% strTest = "This is a test!!" response.write UCase(strTest) %> |
結果:THIS IS A TEST!!
VarType()
作用:返回指示變量子類型的值
語法:VarType(varName)
說明:
以下為引用的內容: <% i = 3 response.write varType(i) %> |
結果:2(數字)詳見 "asp常數"
WeekDay()
作用:返回在一周的第幾天.
語法:WeekDay(date [, firstdayofweek >)
說明:
以下為引用的內容: <% d = #8/4/99# response.write Weekday(d) %> |
結果:4(星期三)
WeekDayName()
作用:返回一周第幾天的名字.
語法:WeekDayName(weekday [, Abb [, firstdayofweek >>)
說明:Abb可選。Boolean 值,指明是否縮寫表示星期各天的名稱。如果省略, 默認值為 False,即不縮寫星期各天的名稱.firstdayofweek指明星期第一天的數值
以下為引用的內容: <% d = #8/4/99# response.write WeekdayName(Weekday(d)) %> |
結果:Wednesday
Year()
作用:返回當前的年份.
語法:Year(date)
說明:
<%=Year(#8/4/99#)%>
結果:1999
分享:ASP實現不存在的網頁就自動發送郵件我們在制作網站的時候,通常會有當訪客的一些錯誤操作或我們網站本身的缺陷,造成某個不存在的頁面被訪問,這時會出現404錯誤提示信息,如果是熱心的訪客可能會給你發一封郵件提示你,當時大部
- 相關鏈接:
- 教程說明:
ASP教程-通過實例講解來學習ASP中的函數。