通過(guò)實(shí)例講解來(lái)學(xué)習(xí)ASP中的函數(shù)_ASP教程
推薦:ASP中Session技巧寫(xiě)過(guò)稍微大型一點(diǎn) ASP 的人都知道,Session 這個(gè)對(duì)象真是好用,它可以用來(lái)記錄使用者私有的資料變量,既安全又方便。但是你真的知道 session 的運(yùn)作原理嗎?或許了解以后,你就再也不太敢使用這
作用:返回一個(gè)數(shù)組
語(yǔ)法:Array(list)
適用的類(lèi)型:字符,數(shù)字均可
| 以下為引用的內(nèi)容: <% Dim myArray() For i = 1 to 7 Redim Preserve myArray(i) myArray(i) = WeekdayName(i) Next %> |
結(jié)果:建立了一個(gè)包含7個(gè)元素的數(shù)組myArray
myArray("Sunday","Monday", ... ... "Saturday")
CInt()
作用:將一個(gè)表達(dá)式轉(zhuǎn)化為數(shù)字類(lèi)型
語(yǔ)法:CInt(表達(dá)式)
適用的類(lèi)型:任何有效的字符均可
| 以下為引用的內(nèi)容: <% f = "234" response.write cINT(f) 2 %> |
結(jié)果:236
轉(zhuǎn)化字符"234"為數(shù)字234,如果字符串為空,則返回0值
CreateObject()
作用:建立和返回一個(gè)已注冊(cè)的ACTIVEX組件的實(shí)例。
語(yǔ)法:CreateObject(objName)
適用的類(lèi)型: objName 是任何一個(gè)有效、已注冊(cè)的ACTIVEX組件的名字。
| 以下為引用的內(nèi)容: <% Set con = Server.CreateObject("ADODB.Connection") %> CStr() |
作用:轉(zhuǎn)化一個(gè)表達(dá)式為字符串。
語(yǔ)法:CStr(expression)
適用類(lèi)型:expression 是任何有效的表達(dá)式
| 以下為引用的內(nèi)容: <% s = 3 2 response.write("The 結(jié)果 is: " & cStr(s)) %> |
結(jié)果: 轉(zhuǎn)化數(shù)字5為字符“5”。
Date()
作用:返回當(dāng)前系統(tǒng)日期。
語(yǔ)法:Date()
適用的類(lèi)型:None。
<%=Date%>
結(jié)果:8/4/99
DateAdd()
作用:返回一個(gè)被改變了的日期。
語(yǔ)法:DateAdd(timeinterval,number,date)
說(shuō)明:timeinterval為所要加入的時(shí)間間隔類(lèi)型;number為要添加的數(shù)量;date為起始日期.
| 以下為引用的內(nèi)容: <% <% 結(jié)果:11/4/99 3:34:45 PM "m" = "month"; 當(dāng)當(dāng)前日期格式為time,那么 "h" = "hour"; DateDiff() |
作用:返回兩個(gè)日期之間的差值。
語(yǔ)法:DateDiff(timeinterval,date1,date2 [, firstdayofweek [, firstweekofyear >>)
說(shuō)明:timeinterval 表示相隔時(shí)間的類(lèi)型,如“M“表示“月”。
| 以下為引用的內(nèi)容: <% 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 are150daysto millenium from 8/4/99
Day()
作用:返回一個(gè)月的第幾日。
語(yǔ)法:Day(date)
說(shuō)明:date 是任何有效的日期。
<%=Day(#8/4/99#)%>
結(jié)果:4
FormatCurrency()
作用:返回表達(dá)式,此表達(dá)式已被格式化為貨幣值
語(yǔ)法:FormatCurrency(Expression [, Digit [, LeadingDigit [, Paren [, GroupDigit >>>>)
說(shuō)明:Digit 指示小數(shù)點(diǎn)右側(cè)顯示位數(shù)的數(shù)值。默認(rèn)值為 -1,指示使用的是計(jì)算機(jī)的區(qū)域設(shè)置;LeadingDigit 三態(tài)常數(shù),指示是否顯示小數(shù)值小數(shù)點(diǎn)前面的零
<%=FormatCurrency(34.3456)%>
結(jié)果:$34.35
FormatDateTime()
作用:返回表達(dá)式,此表達(dá)式已被格式化為日期或時(shí)間
語(yǔ)法:FormatDateTime(Date, [, NamedFormat >)
說(shuō)明:NamedFormat 指示所使用的日期/時(shí)間格式的數(shù)值,如果省略,則使用 vbGeneralDate.
<%=FormatDateTime("08/4/99", vbLongDate)%>
結(jié)果:Wednesday, August 04, 1999
FormatNumber()
作用:返回表達(dá)式,此表達(dá)式已被格式化為數(shù)值
語(yǔ)法:FormatNumber(Expression [, Digit [, LeadingDigit [, Paren [, GroupDigit >>>>)
說(shuō)明:Digit 指示小數(shù)點(diǎn)右側(cè)顯示位數(shù)的數(shù)值。默認(rèn)值為 -1,指示使用的是計(jì)算機(jī)的區(qū)域設(shè)置。; LeadingDigit i指示小數(shù)點(diǎn)右側(cè)顯示位數(shù)的
數(shù)值。默認(rèn)值為 -1,指示使用的是計(jì)算機(jī)的區(qū)域設(shè)置。; Paren 指示小數(shù)點(diǎn)右側(cè)顯示位數(shù)的數(shù)值。默認(rèn)值為 -1,指示使用的是計(jì)算機(jī)的區(qū)域
設(shè)置。; GroupDigit i指示小數(shù)點(diǎn)右側(cè)顯示位數(shù)的數(shù)值。默認(rèn)值為 -1,指示使用的是計(jì)算機(jī)的區(qū)域設(shè)置
<%=FormatNumber(45.324567, 3)%>
結(jié)果: 45.325
FormatPercent()
作用:返回表達(dá)式,此表達(dá)式已被格式化為尾隨有 % 符號(hào)的百分比(乘以 100 )。 (%)
語(yǔ)法:FormatPercent(Expression [, Digit [, LeadingDigit [, Paren [, GroupDigit >>>>)
說(shuō)明:同上
<%=FormatPercent(0.45267, 3)%>
結(jié)果: 45.267%
Hour()
作用:以24時(shí)返回小時(shí)數(shù)
語(yǔ)法:Hour(time)
說(shuō)明:
<%=Hour(#4:45:34 PM#)%>
結(jié)果:16
Instr()
作用:返回字符或字符串在另一個(gè)字符串中第一次出現(xiàn)的位置.
語(yǔ)法:Instr([start, > strToBeSearched, strSearchFor [, compare>)
說(shuō)明:Start為搜索的起始值,strToBeSearched接受搜索的字符串 strSearchFor要搜索的字符compare 比較方式(詳細(xì)見(jiàn)ASP常數(shù))
| 以下為引用的內(nèi)容: <% strText = "This is a test!!" pos = Instr(strText, "a") response.write pos %> |
結(jié)果:9
InstrRev()
作用:同上,只是從字符串的最后一個(gè)搜索起
語(yǔ)法:InstrRev([start, > strToBeSearched, strSearchFor [, compare>)
說(shuō)明:同上.
| 以下為引用的內(nèi)容: <% strText = "This is a test!!" pos = InstrRev(strText, "s") response.write pos %> |
結(jié)果:13
Int()
作用:返回?cái)?shù)值類(lèi)型,不四舍五入。
語(yǔ)法:Int(number)
說(shuō)明:
<%=INT(32.89)%>
結(jié)果:32
IsArray()
作用:判斷一對(duì)象是否為數(shù)組,返回布爾值.
語(yǔ)法:IsArray(name)
說(shuō)明:
| 以下為引用的內(nèi)容: <% strTest = "Test!" response.write IsArray(strTest) %> |
結(jié)果:False
IsDate()
作用:判斷一對(duì)象是否為日期,返回布爾值語(yǔ)法: IsDate(expression) 說(shuō)明: expression is any valid expression.
| 以下為引用的內(nèi)容: <% strTest = "8/4/99" response.write IsDate(strTest) %> |
結(jié)果:True
IsEmpty()
作用:判斷一對(duì)象是否初始化,返回布爾值.
語(yǔ)法:IsEmpty(expression)
說(shuō)明:
| 以下為引用的內(nèi)容: <% Dim i response.write IsEmpty(i) %> |
結(jié)果:True
IsNull()
作用:判斷一對(duì)象是否為空,返回布爾值.
語(yǔ)法:IsNull(expression)
說(shuō)明:
| 以下為引用的內(nèi)容: <% Dim i response.write IsNull(i) %> |
結(jié)果:False
IsNumeric()
作用:判斷一對(duì)象是否為數(shù)字,返回布爾值.
語(yǔ)法:IsNumeric(expression)
說(shuō)明:
| 以下為引用的內(nèi)容: <% i = "345" response.write IsNumeric(i) %> |
結(jié)果:True
就算數(shù)字加了引號(hào),ASP還是認(rèn)為它是數(shù)字。
IsObject()
作用:判斷一對(duì)象是否為對(duì)象,返回布爾值.
語(yǔ)法:IsObject(expression)
說(shuō)明:
| 以下為引用的內(nèi)容: <% Set con = Server.CreateObject( "ADODB.Connection") response.write IsObject(con) %> |
結(jié)果:True
LBound()
作用:返回指定數(shù)組維的最小可用下標(biāo).
語(yǔ)法:Lbound(arrayname [, dimension >)
說(shuō)明:dimension 指明要返回哪一維下界的整數(shù)。使用1表示第一維,2表示第二維,以此類(lèi)推。如果省略 dimension 參數(shù),默認(rèn)值為 1.
| 以下為引用的內(nèi)容: <% i = Array( "Monday","Tuesday","Wednesday") response.write LBound(i) %> |
結(jié)果:0
LCase()
作用:返回字符串的小寫(xiě)形式
語(yǔ)法:Lcase(string)
說(shuō)明:string is any valid string expression.
| 以下為引用的內(nèi)容: <% strTest = "This is a test!" response.write LCase(strTest) %> |
結(jié)果:this is a test!
Left()
作用:返回字符串左邊第length個(gè)字符以前的字符(含第length個(gè)字符).
語(yǔ)法:Left(string, length)
說(shuō)明:
| 以下為引用的內(nèi)容: <% strTest = "This is a test!" response.write Left(strTest, 3) %> |
結(jié)果:Thi
Len()
作用:返回字符串的長(zhǎng)度.
語(yǔ)法:Len(string | varName)
說(shuō)明:
| 以下為引用的內(nèi)容: <% strTest = "This is a test!" response.write Len(strTest) %> |
結(jié)果:15
LTrim()
作用:去掉字符串左邊的空格.
語(yǔ)法:LTrim(string)
說(shuō)明:
| 以下為引用的內(nèi)容: <% strTest = " This is a test!" response.write LTrim(strTest) %> |
結(jié)果:This is a test!
Mid()
作用:返回特定長(zhǎng)度的字符串(從start開(kāi)始,長(zhǎng)度為length).
語(yǔ)法:Mid(string, start [, length >)
說(shuō)明:
| 以下為引用的內(nèi)容: <% strTest = "This is a test! Today is Monday." response.write Mid(strTest, 17, 5) %> |
結(jié)果:Today
Minute()
作用:返回時(shí)間的分釧.
語(yǔ)法:Minute(time)
說(shuō)明:
<%=Minute(#12:45:32 PM#)%>
結(jié)果:45
Month()
作用:返回日期.
語(yǔ)法:Month(date)
說(shuō)明:date is any valid date expression.
<%=Month(#08/04/99#)%>
結(jié)果:8
MonthName()
作用:Returns a string identifying the specified month.
語(yǔ)法:MonthName(month, [, Abb >)
說(shuō)明: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#))%>
結(jié)果:August
Now()
作用:Returns the current system date and time.返回當(dāng)前系統(tǒng)時(shí)間
語(yǔ)法:Now()
說(shuō)明:None
<%=Now%>
結(jié)果: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.
語(yǔ)法:Replace(strToBeSearched, strSearchFor, strReplaceWith [, start [, count [, compare >>>)
| 以下為引用的內(nèi)容: 說(shuō)明: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") %> |
結(jié)果:This is an orange!
Right()
作用:返回字符串右邊第length個(gè)字符以前的字符(含第length個(gè)字符).
語(yǔ)法:Right(string, length)
說(shuō)明:
| 以下為引用的內(nèi)容: <% strTest = "This is an test!" response.write Right(strTest, 3) %> |
結(jié)果:st!
Rnd()
作用:產(chǎn)生一個(gè)隨機(jī)數(shù).
語(yǔ)法:Rnd [ (number) >
說(shuō)明:
| 以下為引用的內(nèi)容: <% Randomize() response.write RND() %> |
結(jié)果:任何一個(gè)在0 到 1 之間的數(shù)
Round()
作用:返回按指定位數(shù)進(jìn)行四舍五入的數(shù)值.
語(yǔ)法:Round(expression [, numRight >)
說(shuō)明:numRight數(shù)字表明小數(shù)點(diǎn)右邊有多少位進(jìn)行四舍五入。如果省略,則 Round 函數(shù)返回整數(shù).
| 以下為引用的內(nèi)容: <% i = 32.45678 response.write Round(i) %> |
結(jié)果:32
Rtrim()
作用:去掉字符串右邊的空格字符串.
語(yǔ)法:Rtrim(string)
說(shuō)明:
| 以下為引用的內(nèi)容: <% strTest = "This is a test!! " response.write RTrim(strTest) %> |
結(jié)果:This is a test!!
Second()
作用:返回秒.
語(yǔ)法:Second(time)
說(shuō)明:
<%=Second(#12:34:28 PM#)%>
結(jié)果:28
StrReverse()
作用:反排一字符串
語(yǔ)法:StrReverse(string)
說(shuō)明
| 以下為引用的內(nèi)容: <% strTest = "This is a test!!" response.write StrReverse(strTest) %> |
結(jié)果:!!tset a si sihT
Time()
作用:返回系統(tǒng)時(shí)間.
語(yǔ)法:Time()
說(shuō)明:
<%=Time%>
結(jié)果:9:58:28 AM
Trim()
作用:去掉字符串左右的空格.
語(yǔ)法:Trim(string)
說(shuō)明:string is any valid string expression.
| 以下為引用的內(nèi)容: <% strTest = " This is a test!! " response.write Trim(strTest) %> |
結(jié)果:This is a test!!
UBound()
作用:返回指定數(shù)組維數(shù)的最大可用下標(biāo).
語(yǔ)法:Ubound(arrayname [, dimension >)
說(shuō)明:dimension (optional) 指定返回哪一維上界的整數(shù)。1 表示第一維,2 表示第二維,以此類(lèi)推。如果省略 dimension 參數(shù),則默認(rèn)值為 1.
| 以下為引用的內(nèi)容: <% i = Array( "Monday","Tuesday","Wednesday") response.write UBound(i) %> |
結(jié)果:2
UCase()
作用:返回字符串的大寫(xiě)形式.
語(yǔ)法:UCase(string)
說(shuō)明:
| 以下為引用的內(nèi)容: <% strTest = "This is a test!!" response.write UCase(strTest) %> |
結(jié)果:THIS IS A TEST!!
VarType()
作用:返回指示變量子類(lèi)型的值
語(yǔ)法:VarType(varName)
說(shuō)明:
| 以下為引用的內(nèi)容: <% i = 3 response.write varType(i) %> |
結(jié)果:2(數(shù)字)詳見(jiàn) "asp常數(shù)"
WeekDay()
作用:返回在一周的第幾天.
語(yǔ)法:WeekDay(date [, firstdayofweek >)
說(shuō)明:
| 以下為引用的內(nèi)容: <% d = #8/4/99# response.write Weekday(d) %> |
結(jié)果:4(星期三)
WeekDayName()
作用:返回一周第幾天的名字.
語(yǔ)法:WeekDayName(weekday [, Abb [, firstdayofweek >>)
說(shuō)明:Abb可選。Boolean 值,指明是否縮寫(xiě)表示星期各天的名稱。如果省略, 默認(rèn)值為 False,即不縮寫(xiě)星期各天的名稱.firstdayofweek指明星期第一天的數(shù)值
| 以下為引用的內(nèi)容: <% d = #8/4/99# response.write WeekdayName(Weekday(d)) %> |
結(jié)果:Wednesday
Year()
作用:返回當(dāng)前的年份.
語(yǔ)法:Year(date)
說(shuō)明:
<%=Year(#8/4/99#)%>
結(jié)果:1999
分享:ASP實(shí)現(xiàn)不存在的網(wǎng)頁(yè)就自動(dòng)發(fā)送郵件我們?cè)谥谱骶W(wǎng)站的時(shí)候,通常會(huì)有當(dāng)訪客的一些錯(cuò)誤操作或我們網(wǎng)站本身的缺陷,造成某個(gè)不存在的頁(yè)面被訪問(wèn),這時(shí)會(huì)出現(xiàn)404錯(cuò)誤提示信息,如果是熱心的訪客可能會(huì)給你發(fā)一封郵件提示你,當(dāng)時(shí)大部
- asp FSO 讀寫(xiě)文件本文件實(shí)現(xiàn)代碼
- asp中isNull、isEmpty和空字符串的區(qū)別
- asp獲取用戶真實(shí)IP地址的方法
- asp連接sqlserver數(shù)據(jù)庫(kù)實(shí)現(xiàn)代碼
- asp中正則表達(dá)式過(guò)濾html代碼函數(shù)
- asp中g(shù)et post提交表單區(qū)別
- 網(wǎng)頁(yè)模板:ASP內(nèi)建對(duì)象Request
- xmlhttp的open方法使用詳解
- ASP的常用的自定義函數(shù)大全
- asp中用for循環(huán)的一個(gè)小技巧
- eWebEditor v3.8 列目錄
- ASP無(wú)組件分頁(yè)實(shí)現(xiàn)思路及代碼
ASP教程Rss訂閱編程教程搜索
ASP教程推薦
- 用ASP編程實(shí)現(xiàn)網(wǎng)絡(luò)內(nèi)容快速查找
- 淺談ASP編程的思路與糾錯(cuò)
- ASP基礎(chǔ)教程之ASP AdRotator 組件的使用
- ASP實(shí)例:一個(gè)簡(jiǎn)單的ASP無(wú)組件上傳類(lèi)
- ASP實(shí)例講解:用分頁(yè)符實(shí)現(xiàn)長(zhǎng)文章分頁(yè)顯示
- 經(jīng)典!5分鐘編寫(xiě)一個(gè)ASP論壇
- 淺析js返回字符串中某個(gè)字符的出現(xiàn)次數(shù)
- ASP教程:自己寫(xiě)的數(shù)據(jù)庫(kù)操作類(lèi)
- ASP內(nèi)置對(duì)象Request和Response的詳解
- 怎樣用asp程序讀取網(wǎng)站的alexa世界排名
- 相關(guān)鏈接:
復(fù)制本頁(yè)鏈接| 搜索通過(guò)實(shí)例講解來(lái)學(xué)習(xí)ASP中的函數(shù)
- 教程說(shuō)明:
ASP教程-通過(guò)實(shí)例講解來(lái)學(xué)習(xí)ASP中的函數(shù)
。