天天看點

asp 常用函數用法

Array() 

   FUNCTION: 傳回一個數組 

   SYNTAX: Array(list) 

   ARGUMENTS: 字元,數字均可 

   EXAMPLE: <% 

Dim myArray() 

For i = 1 to 7 

Redim Preserve myArray(i) 

myArray(i) = WeekdayName(i) 

Next 

%> 

   RESULT: 建立了一個包含7個元素的數組myArray 

   myArray("Sunday","Monday", ... ... "Saturday") 

CInt() 

   FUNCTION: 将一個表達式轉化為數字類型 

   SYNTAX: CInt(expression) 

   ARGUMENTS: 任何有效的字元均可 

f = "234" 

response.write cINT(f) + 2 

   RESULT: 236 

   轉化字元"234"為數字"234",如果字元串為空,則傳回0值 

CreateObject() 

   FUNCTION: 建立和傳回一個已注冊的ACTIVEX元件的執行個體。 

   SYNTAX: CreateObject(objName) 

   ARGUMENTS: objName 是任何一個有效、已注冊的ACTIVEX元件的名字. 

Set con = Server.CreateObject("ADODB.Connection") 

   RESULT: 

CStr() 

   FUNCTION: 轉化一個表達式為字元串. 

   SYNTAX: CStr(expression) 

   ARGUMENTS: expression 是任何有效的表達式。 

s = 3 + 2 

response.write "The result is: " & cStr(s) 

   RESULT: 轉化數字“5”為字元“5”。 

Date() 

   FUNCTION: 傳回目前系統日期. 

   SYNTAX: Date() 

   ARGUMENTS: None. 

   EXAMPLE: <%=Date%> 

   RESULT: 8/4/99 

DateAdd() 

   FUNCTION: 傳回一個被改變了的日期。 

   SYNTAX: DateAdd(timeinterval,number,date) 

   ARGUMENTS: timeinterval is the time interval to add; number is amount of time intervals to add; and date is the starting date. 

currentDate = #8/4/99# 

newDate = DateAdd("m",3,currentDate) 

response.write newDate 

<% 

currentDate = #12:34:45 PM# 

newDate = DateAdd("h",3,currentDate) 

   RESULT: 11/4/99 

   3:34:45 PM 

   "m" = "month"; 

   "d" = "day"; 

   If currentDate is in time format then, 

   "h" = "hour"; 

   "s" = "second"; 

DateDiff() 

   FUNCTION: 傳回兩個日期之間的內插補點 。 

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

   ARGUMENTS: 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." 

   RESULT: 從8/4/99 到2000年還有 150 天. 

Day() 

   FUNCTION: 傳回一個月的第幾日 . 

   SYNTAX: Day(date) 

   ARGUMENTS: date 是任何有效的日期。 

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

   RESULT: 4 

FormatCurrency() 

   FUNCTION: 傳回表達式,此表達式已被格式化為貨币值 

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

   ARGUMENTS: Digit 訓示小數點右側顯示位數的數值。預設值為 -1,訓示使用的是計算機的區域設定;   LeadingDigit 三态常數,訓示是否顯示小數值小數點前面的零。 

   EXAMPLE: <%=FormatCurrency(34.3456)%> 

   RESULT: $34.35 

FormatDateTime() 

   FUNCTION: 傳回表達式,此表達式已被格式化為日期或時間 

   SYNTAX: FormatDateTime(Date, [, NamedFormat>) 

   ARGUMENTS: NamedFormat 訓示所使用的日期/時間格式的數值,如果省略,則使用 vbGeneralDate. 

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

   RESULT: Wednesday, August 04, 1999 

FormatNumber() 

   FUNCTION: 傳回表達式,此表達式已被格式化為數值. 

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

   ARGUMENTS: Digit 訓示小數點右側顯示位數的數值。預設值為 -1,訓示使用的是計算機的區域設定。; LeadingDigit i訓示小數點右側顯示位數的數值。預設值為 -1,訓示使用的是計算機的區域設定。; Paren 訓示小數點右側顯示位數的數值。預設值為 -1,訓示使用的是計算機的區域設定。; GroupDigit i訓示小數點右側顯示位數的數值。預設值為 -1,訓示使用的是計算機的區域設定。. 

   EXAMPLE: <%=FormatNumber(45.324567, 3)%> 

   RESULT: 45.325 

FormatPercent() 

   FUNCTION: 傳回表達式,此表達式已被格式化為尾随有 % 符号的百分比(乘以 100 )。 (%) 

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

   ARGUMENTS: 同上. 

   EXAMPLE: <%=FormatPercent(0.45267, 3)%> 

   RESULT: 45.267% 

Hour() 

   FUNCTION: 以24時傳回小時數. 

   SYNTAX: Hour(time) 

   ARGUMENTS: 

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

   RESULT: 16 

   (Hour has been converted to 24-hour system) 

Instr() 

   FUNCTION: 傳回字元或字元串在另一個字元串中第一次出現的位置. 

   SYNTAX: Instr([start, > strToBeSearched, strSearchFor [, compare>) 

   ARGUMENTS: Start為搜尋的起始值,strToBeSearched接受搜尋的字元串 strSearchFor要搜尋的字元compare 比較方式(詳細見ASP常數) 

strText = "This is a test!!" 

pos = Instr(strText, "a") 

response.write pos 

   RESULT: 9 

InstrRev() 

   FUNCTION: 同上,隻是從字元串的最後一個搜尋起 

   SYNTAX: InstrRev([start, > strToBeSearched, strSearchFor [, compare>) 

pos = InstrRev(strText, "s") 

   RESULT: 13 

Int() 

   FUNCTION: 傳回數值類型,不四舍五入。 

   SYNTAX: Int(number) 

   EXAMPLE: <%=INT(32.89)%> 

   RESULT: 32 

IsArray() 

   FUNCTION: 判斷一對象是否為數組,傳回布爾值 . 

   SYNTAX: IsArray(name) 

strTest = "Test!" 

response.write IsArray(strTest) 

   RESULT: False 

IsDate() 

   FUNCTION: 判斷一對象是否為日期,傳回布爾值 

   SYNTAX: IsDate(expression) 

   ARGUMENTS: expression is any valid expression. 

strTest = "8/4/99" 

response.write IsDate(strTest) 

   RESULT: True 

IsEmpty() 

   FUNCTION: 判斷一對象是否初始化,傳回布爾值. 

   SYNTAX: IsEmpty(expression) 

Dim i 

response.write IsEmpty(i) 

IsNull() 

   FUNCTION: 判斷一對象是否為空,傳回布爾值. 

   SYNTAX: IsNull(expression) 

response.write IsNull(i) 

IsNumeric() 

   FUNCTION: 判斷一對象是否為數字,傳回布爾值. 

   SYNTAX: IsNumeric(expression) 

i = "345" 

response.write IsNumeric(i) 

   就算數字加了引号,ASP還是認為它是數字。 

IsObject() 

   FUNCTION: 判斷一對象是否為對象,傳回布爾值. 

   SYNTAX: IsObject(expression) 

response.write IsObject(con) 

LBound() 

   FUNCTION: 傳回指定數組維的最小可用下标. 

   SYNTAX: Lbound(arrayname [, dimension>) 

   ARGUMENTS: dimension 指明要傳回哪一維下界的整數。使用 1 表示第一維,2 表示第二維,以此類  推。如果省略 dimension 參數,預設值為 1. 

i = Array("Monday","Tuesday","Wednesday") 

response.write LBound(i) 

   RESULT: 0 

LCase() 

   FUNCTION: 傳回字元串的小寫形式 

   SYNTAX: Lcase(string) 

   ARGUMENTS: string is any valid string expression. 

strTest = "This is a test!" 

response.write LCase(strTest) 

   RESULT: this is a test! 

Left() 

   FUNCTION: 傳回字元串左邊第length個字元以前的字元(含第length個字元). 

   SYNTAX: Left(string, length) 

response.write Left(strTest, 3) 

   RESULT: Thi 

Len() 

   FUNCTION: 傳回字元串的長度. 

   SYNTAX: Len(string | varName) 

response.write Len(strTest) 

   RESULT: 15 

LTrim() 

   FUNCTION: 去掉字元串左邊的空格. 

   SYNTAX: LTrim(string) 

strTest = " This is a test!" 

response.write LTrim(strTest) 

   RESULT: This is a test! 

Mid() 

   FUNCTION: 傳回特定長度的字元串(從start開始,長度為length). 

   SYNTAX: Mid(string, start [, length>) 

strTest = "This is a test! Today is Monday." 

response.write Mid(strTest, 17, 5) 

   RESULT: Today 

Minute() 

   FUNCTION: 傳回時間的分钏. 

   SYNTAX: Minute(time) 

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

   RESULT: 45 

Month() 

   FUNCTION: 傳回日期. 

   SYNTAX: Month(date) 

   ARGUMENTS: date is any valid date expression. 

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

   RESULT: 8 

MonthName() 

   FUNCTION: Returns a string identifying the specified month. 

   SYNTAX: MonthName(month, [, Abb>) 

   ARGUMENTS: 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. 

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

   RESULT: August 

Now() 

   FUNCTION: Returns the current system date and time. 

   SYNTAX: Now() 

   ARGUMENTS: None 

   EXAMPLE: <%=Now%> 

   RESULT: 8/4/99 9:30:16 AM 

Replace() 

   FUNCTION: Returns a string in which a specified sub-string has been replaced with another substring a specified number of times. 

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

   ARGUMENTS: 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") 

   RESULT: This is an orange! 

Right() 

   FUNCTION: 傳回字元串右邊第length個字元以前的字元(含第length個字元). 

   SYNTAX: Right(string, length) 

   ARGUMENTS: . 

strTest = "This is an test!" 

response.write Right(strTest, 3) 

   RESULT: st! 

Rnd() 

   FUNCTION: 産生一個随機數. 

   SYNTAX: Rnd [ (number) > 

Randomize() 

response.write RND() 

   RESULT: 任何一個在0 到 1 之間的數 

Round() 

   FUNCTION: 傳回按指定位數進行四舍五入的數值. 

   SYNTAX: Round(expression [, numRight>) 

   ARGUMENTS: numRight數字表明小數點右邊有多少位進行四舍五入。如果省略,則 Round 函數傳回整數. 

i = 32.45678 

response.write Round(i) 

Rtrim() 

   FUNCTION: 去掉字元串右邊的字元串. 

   SYNTAX: Rtrim(string) 

strTest = "This is a test!! " 

response.write RTrim(strTest) 

   RESULT: This is a test!! 

Second() 

   FUNCTION: 傳回秒. 

   SYNTAX: Second(time) 

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

   RESULT: 28 

StrReverse() 

   FUNCTION: 反排一字元串 

   SYNTAX: StrReverse(string) 

strTest = "This is a test!!" 

response.write StrReverse(strTest) 

   RESULT: !!tset a si sihT 

Time() 

   FUNCTION: 傳回系統時間. 

   SYNTAX: Time() 

   EXAMPLE: <%=Time%> 

   RESULT: 9:58:28 AM 

Trim() 

   FUNCTION: 去掉字元串左右的空格. 

   SYNTAX: Trim(string) 

strTest = " This is a test!! " 

response.write Trim(strTest) 

UBound() 

   FUNCTION: 傳回指定數組維數的最大可用下标. 

   SYNTAX: Ubound(arrayname [, dimension>) 

   ARGUMENTS: dimension (optional) 指定傳回哪一維上界的整數。1 表示第一維,2 表示第二維,以此類推。如果省略 dimension 參數,則預設值為 1. 

response.write UBound(i) 

   RESULT: 2 

UCase() 

   FUNCTION: 傳回字元串的大寫形式. 

   SYNTAX: UCase(string) 

response.write UCase(strTest) 

   RESULT: THIS IS A TEST!! 

VarType() 

   FUNCTION: 傳回訓示變量子類型的值 

   SYNTAX: VarType(varName) 

i = 3 

response.write varType(i) 

   RESULT: 2(數字)詳見"asp常數" 

WeekDay() 

   FUNCTION: 傳回在一周的第幾天. 

   SYNTAX: WeekDay(date [, firstdayofweek>) 

d = #8/4/99# 

response.write Weekday(d) 

   RESULT: 4(星期三) 

WeekDayName() 

   FUNCTION: 傳回一周第幾天的名字. 

   SYNTAX: WeekDayName(weekday [, Abb [, firstdayofweek>>) 

   ARGUMENTS: Abb可選。Boolean 值,指明是否縮寫表示星期各天的名稱。如果省略, 預設值為 False,即不縮寫星期各天的名稱.firstdayofweek指明星期第一天的數值 

response.write WeekdayName(Weekday(d)) 

   RESULT: Wednesday 

Year() 

   FUNCTION: 傳回目前的年份. 

   SYNTAX: Year(date) 

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

   RESULT: 1999

本文轉自 筆頭 51CTO部落格,原文連結:http://blog.51cto.com/douvip/15416,如需轉載請自行聯系原作者

繼續閱讀