国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > ASP > 正文

通過實例講解來學(xué)習(xí)ASP中的函數(shù)_ASP教程

2024-05-04 11:03:29
字體:
供稿:網(wǎng)友

推薦:ASP中Session技巧
寫過稍微大型一點 ASP 的人都知道,Session 這個對象真是好用,它可以用來記錄使用者私有的資料變量,既安全又方便。但是你真的知道 session 的運作原理嗎?或許了解以后,你就再也不太敢使用這

作用:返回一個數(shù)組

語法:Array(list)

適用的類型:字符,數(shù)字均可

以下為引用的內(nèi)容:
<%
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()

作用:將一個表達(dá)式轉(zhuǎn)化為數(shù)字類型

語法:CInt(表達(dá)式)

適用的類型:任何有效的字符均可


以下為引用的內(nèi)容:
<%
f = "234"
response.write cINT(f) 2
%>

結(jié)果:236

轉(zhuǎn)化字符"234"為數(shù)字234,如果字符串為空,則返回0值

CreateObject()

作用:建立和返回一個已注冊的ACTIVEX組件的實例。

語法:CreateObject(objName)

適用的類型: objName 是任何一個有效、已注冊的ACTIVEX組件的名字。

以下為引用的內(nèi)容:
<%
Set con = Server.CreateObject("ADODB.Connection")
%>
CStr()

作用:轉(zhuǎn)化一個表達(dá)式為字符串。

語法:CStr(expression)

適用類型: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)日期。

語法:Date()

適用的類型:None。

<%=Date%>

結(jié)果:8/4/99

DateAdd()

作用:返回一個被改變了的日期。

語法:DateAdd(timeinterval,number,date)

說明:timeinterval為所要加入的時間間隔類型;number為要添加的數(shù)量;date為起始日期.

以下為引用的內(nèi)容:

<%  
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";

當(dāng)當(dāng)前日期格式為time,那么

"h" = "hour";
"s" = "second";

DateDiff()

作用:返回兩個日期之間的差值。

語法:DateDiff(timeinterval,date1,date2 [, firstdayofweek [, firstweekofyear >>)

說明:timeinterval 表示相隔時間的類型,如“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()

作用:返回一個月的第幾日。

語法:Day(date)

說明:date 是任何有效的日期。

<%=Day(#8/4/99#)%>

結(jié)果:4

FormatCurrency()

作用:返回表達(dá)式,此表達(dá)式已被格式化為貨幣值

語法:FormatCurrency(Expression [, Digit [, LeadingDigit [, Paren [, GroupDigit >>>>)

說明:Digit 指示小數(shù)點右側(cè)顯示位數(shù)的數(shù)值。默認(rèn)值為 -1,指示使用的是計算機(jī)的區(qū)域設(shè)置;LeadingDigit 三態(tài)常數(shù),指示是否顯示小數(shù)值小數(shù)點前面的零

<%=FormatCurrency(34.3456)%>

結(jié)果:$34.35

FormatDateTime()

作用:返回表達(dá)式,此表達(dá)式已被格式化為日期或時間

語法:FormatDateTime(Date, [, NamedFormat >)

說明:NamedFormat 指示所使用的日期/時間格式的數(shù)值,如果省略,則使用 vbGeneralDate.

<%=FormatDateTime("08/4/99", vbLongDate)%>

結(jié)果:Wednesday, August 04, 1999

FormatNumber()

作用:返回表達(dá)式,此表達(dá)式已被格式化為數(shù)值

語法:FormatNumber(Expression [, Digit [, LeadingDigit [, Paren [, GroupDigit >>>>)

說明:Digit 指示小數(shù)點右側(cè)顯示位數(shù)的數(shù)值。默認(rèn)值為 -1,指示使用的是計算機(jī)的區(qū)域設(shè)置。; LeadingDigit i指示小數(shù)點右側(cè)顯示位數(shù)的
數(shù)值。默認(rèn)值為 -1,指示使用的是計算機(jī)的區(qū)域設(shè)置。; Paren 指示小數(shù)點右側(cè)顯示位數(shù)的數(shù)值。默認(rèn)值為 -1,指示使用的是計算機(jī)的區(qū)域
設(shè)置。; GroupDigit i指示小數(shù)點右側(cè)顯示位數(shù)的數(shù)值。默認(rèn)值為 -1,指示使用的是計算機(jī)的區(qū)域設(shè)置

<%=FormatNumber(45.324567, 3)%>

結(jié)果: 45.325

FormatPercent()

作用:返回表達(dá)式,此表達(dá)式已被格式化為尾隨有 % 符號的百分比(乘以 100 )。 (%)

語法:FormatPercent(Expression [, Digit [, LeadingDigit [, Paren [, GroupDigit >>>>)

說明:同上

<%=FormatPercent(0.45267, 3)%>

結(jié)果: 45.267%

Hour()

作用:以24時返回小時數(shù)

語法:Hour(time)

說明:

<%=Hour(#4:45:34 PM#)%>

結(jié)果:16

Instr()

作用:返回字符或字符串在另一個字符串中第一次出現(xiàn)的位置.

語法:Instr([start, > strToBeSearched, strSearchFor [, compare>)

說明:Start為搜索的起始值,strToBeSearched接受搜索的字符串 strSearchFor要搜索的字符compare 比較方式(詳細(xì)見ASP常數(shù))

以下為引用的內(nèi)容:
<%
strText = "This is a test!!"
pos = Instr(strText, "a")
response.write pos
%>

結(jié)果:9

InstrRev()

作用:同上,只是從字符串的最后一個搜索起

語法:InstrRev([start, > strToBeSearched, strSearchFor [, compare>)

說明:同上.

以下為引用的內(nèi)容:
<%
strText = "This is a test!!"
pos = InstrRev(strText, "s")
response.write pos
%>

結(jié)果:13

Int()

作用:返回數(shù)值類型,不四舍五入。

語法:Int(number)

說明:

<%=INT(32.89)%>

結(jié)果:32

IsArray()

作用:判斷一對象是否為數(shù)組,返回布爾值.

語法:IsArray(name)

說明:

以下為引用的內(nèi)容:
<%
strTest = "Test!"
response.write IsArray(strTest)
%>

結(jié)果:False

IsDate()

作用:判斷一對象是否為日期,返回布爾值語法: IsDate(expression) 說明: expression is any valid expression.

以下為引用的內(nèi)容:
<%
strTest = "8/4/99"
response.write IsDate(strTest)
%>

結(jié)果:True

IsEmpty()

作用:判斷一對象是否初始化,返回布爾值.

語法:IsEmpty(expression)

說明:

以下為引用的內(nèi)容:
<% 
Dim i
response.write IsEmpty(i)
%>

結(jié)果:True

IsNull()

作用:判斷一對象是否為空,返回布爾值.

語法:IsNull(expression)

說明:

以下為引用的內(nèi)容:
<%
Dim i
response.write IsNull(i)
%>

結(jié)果:False

IsNumeric()

作用:判斷一對象是否為數(shù)字,返回布爾值.

語法:IsNumeric(expression)

說明:

以下為引用的內(nèi)容:
<%
i = "345"
response.write IsNumeric(i)
%>

結(jié)果:True

就算數(shù)字加了引號,ASP還是認(rèn)為它是數(shù)字。

IsObject()

作用:判斷一對象是否為對象,返回布爾值.

語法:IsObject(expression)

說明:

以下為引用的內(nèi)容:
<%  
Set con = Server.CreateObject( "ADODB.Connection")
response.write IsObject(con)
%>

結(jié)果:True

LBound()

作用:返回指定數(shù)組維的最小可用下標(biāo).

語法:Lbound(arrayname [, dimension >)

說明:dimension 指明要返回哪一維下界的整數(shù)。使用1表示第一維,2表示第二維,以此類推。如果省略 dimension 參數(shù),默認(rèn)值為 1.

以下為引用的內(nèi)容:
<%
i = Array( "Monday","Tuesday","Wednesday")
response.write LBound(i)
%>

結(jié)果:0

LCase()

作用:返回字符串的小寫形式

語法:Lcase(string)

說明:string is any valid string expression.

以下為引用的內(nèi)容:
<%
strTest = "This is a test!"
response.write LCase(strTest)
%>

結(jié)果:this is a test!

Left()

作用:返回字符串左邊第length個字符以前的字符(含第length個字符).

語法:Left(string, length)

說明:

以下為引用的內(nèi)容:
<%
strTest = "This is a test!"
response.write Left(strTest, 3)
%>

結(jié)果:Thi

Len()

作用:返回字符串的長度.

語法:Len(string | varName)

說明:

以下為引用的內(nèi)容:
<%
strTest = "This is a test!"
response.write Len(strTest)
%>

結(jié)果:15

LTrim()
作用:去掉字符串左邊的空格.

語法:LTrim(string)

說明:

以下為引用的內(nèi)容:
<%
strTest = " This is a test!"
response.write LTrim(strTest)
%>

結(jié)果:This is a test!

Mid()

作用:返回特定長度的字符串(從start開始,長度為length).

語法:Mid(string, start [, length >)

說明:

以下為引用的內(nèi)容:
<%
strTest = "This is a test! Today is Monday."
response.write Mid(strTest, 17, 5)
%>

結(jié)果:Today

Minute()

作用:返回時間的分釧.

語法:Minute(time)

說明:

<%=Minute(#12:45:32 PM#)%>

結(jié)果:45

Month()

作用:返回日期.

語法:Month(date)

說明:date is any valid date expression.

<%=Month(#08/04/99#)%>

結(jié)果: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#))%>

結(jié)果:August

Now()

作用:Returns the current system date and time.返回當(dāng)前系統(tǒng)時間

語法:Now()

說明: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.

語法:Replace(strToBeSearched, strSearchFor, strReplaceWith [, start [, count [, compare >>>)

以下為引用的內(nèi)容:
說明: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個字符以前的字符(含第length個字符).

語法:Right(string, length)

說明:

以下為引用的內(nèi)容:
<%
strTest = "This is an test!"
response.write Right(strTest, 3)
%>

結(jié)果:st!

Rnd()

作用:產(chǎn)生一個隨機(jī)數(shù).

語法:Rnd [ (number) >

說明:

以下為引用的內(nèi)容:
<%
Randomize()
response.write RND()
%>

結(jié)果:任何一個在0 到 1 之間的數(shù)

Round()

作用:返回按指定位數(shù)進(jìn)行四舍五入的數(shù)值.

語法:Round(expression [, numRight >)

說明:numRight數(shù)字表明小數(shù)點右邊有多少位進(jìn)行四舍五入。如果省略,則 Round 函數(shù)返回整數(shù).

以下為引用的內(nèi)容:
<%
i = 32.45678
response.write Round(i)
%>

結(jié)果:32

Rtrim()

作用:去掉字符串右邊的空格字符串.

語法:Rtrim(string)

說明:

以下為引用的內(nèi)容:
<%
strTest = "This is a test!! "
response.write RTrim(strTest)
%>

結(jié)果:This is a test!!

Second()

作用:返回秒.

語法:Second(time)

說明:

<%=Second(#12:34:28 PM#)%>

結(jié)果:28

StrReverse()

作用:反排一字符串

語法:StrReverse(string)

說明

以下為引用的內(nèi)容:
<%
strTest = "This is a test!!"
response.write StrReverse(strTest)
%>

結(jié)果:!!tset a si sihT

Time()

作用:返回系統(tǒng)時間.

語法:Time()

說明:

<%=Time%>

結(jié)果:9:58:28 AM

Trim()

作用:去掉字符串左右的空格.

語法:Trim(string)

說明: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).

語法:Ubound(arrayname [, dimension >)

說明:dimension (optional) 指定返回哪一維上界的整數(shù)。1 表示第一維,2 表示第二維,以此類推。如果省略 dimension 參數(shù),則默認(rèn)值為 1.

以下為引用的內(nèi)容:
<%
i = Array( "Monday","Tuesday","Wednesday")
response.write UBound(i)
%>

結(jié)果:2

UCase()

作用:返回字符串的大寫形式.

語法:UCase(string)

說明:

以下為引用的內(nèi)容:
<%
strTest = "This is a test!!"
response.write UCase(strTest)
%>

結(jié)果:THIS IS A TEST!!

VarType()

作用:返回指示變量子類型的值

語法:VarType(varName)

說明:

以下為引用的內(nèi)容:
<%
i = 3
response.write varType(i)
%>

結(jié)果:2(數(shù)字)詳見 "asp常數(shù)"

WeekDay()

作用:返回在一周的第幾天.

語法:WeekDay(date [, firstdayofweek >)

說明:

以下為引用的內(nèi)容:
<%
d = #8/4/99#
response.write Weekday(d)
%>

結(jié)果:4(星期三)

WeekDayName()

作用:返回一周第幾天的名字.

語法:WeekDayName(weekday [, Abb [, firstdayofweek >>)

說明:Abb可選。Boolean 值,指明是否縮寫表示星期各天的名稱。如果省略, 默認(rèn)值為 False,即不縮寫星期各天的名稱.firstdayofweek指明星期第一天的數(shù)值

以下為引用的內(nèi)容:
<%
d = #8/4/99#
response.write WeekdayName(Weekday(d))
%>

結(jié)果:Wednesday

Year()

作用:返回當(dāng)前的年份.

語法:Year(date)

說明:

<%=Year(#8/4/99#)%>

結(jié)果:1999

分享:ASP實現(xiàn)不存在的網(wǎng)頁就自動發(fā)送郵件
我們在制作網(wǎng)站的時候,通常會有當(dāng)訪客的一些錯誤操作或我們網(wǎng)站本身的缺陷,造成某個不存在的頁面被訪問,這時會出現(xiàn)404錯誤提示信息,如果是熱心的訪客可能會給你發(fā)一封郵件提示你,當(dāng)時大部

發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 玉溪市| 邵阳县| 嘉鱼县| 固原市| 马关县| 微博| 蓬莱市| 巴林左旗| 图片| 忻州市| 常山县| 霍邱县| 资溪县| 色达县| 玛沁县| 房山区| 湖北省| 辉南县| 肃北| 南充市| 宿州市| 本溪| 竹山县| 平果县| 通榆县| 乐平市| 普宁市| 通河县| 宝丰县| 昆明市| 游戏| 周至县| 若羌县| 娱乐| 青铜峡市| 凭祥市| 涞水县| 泸定县| 浪卡子县| 图木舒克市| 宣汉县|