Array()
FUNCTION: 返回一個(gè)數(shù)組
SYNTAX: Array(list)
ARGUMENTS: 字符,數(shù)字均可
EXAMPLE: <%
Dim myArray()
For i = 1 to 7
Redim Preserve myArray(i)
myArray(i) = WeekdayName(i)
Next
%>
RESULT: 建立了一個(gè)包含7個(gè)元素的數(shù)組myArray
myArray("Sunday","Monday", ... ... "Saturday")
CInt()
FUNCTION: 將一個(gè)表達(dá)式轉(zhuǎn)化為數(shù)字類(lèi)型
SYNTAX: CInt(expression)
ARGUMENTS: 任何有效的字符均可
EXAMPLE: <%
f = "234"
response.write cINT(f) + 2
%>
RESULT: 236
轉(zhuǎn)化字符"234"為數(shù)字"234",如果字符串為空,則返回0值
CreateObject()
FUNCTION: 建立和返回一個(gè)已注冊(cè)的ACTIVEX組件的實(shí)例。
SYNTAX: CreateObject(objName)
ARGUMENTS: objName 是任何一個(gè)有效、已注冊(cè)的ACTIVEX組件的名字.
EXAMPLE: <%
Set con = Server.CreateObject("ADODB.Connection")
%>
RESULT:
CStr()
FUNCTION: 轉(zhuǎn)化一個(gè)表達(dá)式為字符串.
SYNTAX: CStr(expression)
ARGUMENTS: expression 是任何有效的表達(dá)式。
EXAMPLE: <%
s = 3 + 2
response.write "The result is: " & cStr(s)
%>
RESULT: 轉(zhuǎn)化數(shù)字“5”為字符“5”。
Date()
FUNCTION: 返回當(dāng)前系統(tǒng)日期.
SYNTAX: Date()
ARGUMENTS: None.
EXAMPLE: <%=Date%>
RESULT: 8/4/99
DateAdd()
FUNCTION: 返回一個(gè)被改變了的日期。
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.
EXAMPLE: <%
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
%>
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: 返回兩個(gè)日期之間的差值 。
SYNTAX: DateDiff(timeinterval,date1,date2 [, firstdayofweek ][,
firstweekofyear]])
ARGUMENTS: timeinterval 表示相隔時(shí)間的類(lèi)型,如“M“表示“月”。
EXAMPLE: <%
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: 返回一個(gè)月的第幾日 .
SYNTAX: Day(date)
ARGUMENTS: date 是任何有效的日期!
EXAMPLE: <%=Day(#8/4/99#)%>
RESULT: 4
FormatCurrency()
FUNCTION: 返回表達(dá)式,此表達(dá)式已被格式化為貨幣值
SYNTAX: FormatCurrency(Expression [, Digit ][, LeadingDigit ][, Paren ][,
GroupDigit]]]])
ARGUMENTS: Digit 指示小數(shù)點(diǎn)右側(cè)顯示位數(shù)的數(shù)值。默認(rèn)值為 -1,指示使用的是
計(jì)算機(jī)的區(qū)域設(shè)置; LeadingDigit 三態(tài)常數(shù),指示是否顯示小數(shù)值小數(shù)點(diǎn)前面的
零。
EXAMPLE: <%=FormatCurrency(34.3456)%>
RESULT: $34.35
FormatDateTime()
FUNCTION: 返回表達(dá)式,此表達(dá)式已被格式化為日期或時(shí)間
SYNTAX: FormatDateTime(Date, [, NamedFormat])
ARGUMENTS: NamedFormat 指示所使用的日期/時(shí)間格式的數(shù)值,如果省略,則使用
vbGeneralDate.
EXAMPLE: <%=FormatDateTime("08/4/99", vbLongDate)%>
RESULT: Wednesday, August 04, 1999
FormatNumber()
FUNCTION: 返回表達(dá)式,此表達(dá)式已被格式化為數(shù)值.
SYNTAX: FormatNumber(Expression [, Digit ][, LeadingDigit ][, Paren ][,
GroupDigit]]]])
ARGUMENTS: 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è)置。.
EXAMPLE: <%=FormatNumber(45.324567, 3)%>
RESULT: 45.325
FormatPercent()
FUNCTION: 返回表達(dá)式,此表達(dá)式已被格式化為尾隨有 % 符號(hào)的百分比(乘以
100 )。 (%)
SYNTAX: FormatPercent(Expression [, Digit ][, LeadingDigit ][, Paren ][,
GroupDigit]]]])
ARGUMENTS: 同上.
EXAMPLE: <%=FormatPercent(0.45267, 3)%>
RESULT: 45.267%
Hour()
FUNCTION: 以24時(shí)返回小時(shí)數(shù).
SYNTAX: Hour(time)
ARGUMENTS:
EXAMPLE: <%=Hour(#4:45:34 PM#)%>
RESULT: 16
(Hour has been converted to 24-hour system)
Instr()
FUNCTION: 返回字符或字符串在另一個(gè)字符串中第一次出現(xiàn)的位置.
SYNTAX: Instr([start, ] strToBeSearched, strSearchFor [, compare])
ARGUMENTS: Start為搜索的起始值,strToBeSearched接受搜索的字符串
strSearchFor要搜索的字符.compare比較方式(詳細(xì)見(jiàn)ASP常數(shù))
EXAMPLE: <%
strText = "This is a test!!"
pos = Instr(strText, "a")
response.write pos
%>
RESULT: 9
InstrRev()
FUNCTION: 同上,只是從字符串的最后一個(gè)搜索起
SYNTAX: InstrRev([start, ] strToBeSearched, strSearchFor [, compare])
ARGUMENTS: 同上.
EXAMPLE: <%
strText = "This is a test!!"
pos = InstrRev(strText, "s")
response.write pos
%>
RESULT: 13
Int()
FUNCTION: 返回?cái)?shù)值類(lèi)型,不四舍五入,注意取值是不大于它的整數(shù)。
SYNTAX: Int(number)
ARGUMENTS:
EXAMPLE: <%=INT(32.89)%> <%=int(-3.33)%>
RESULT: 32 -4
IsArray()
FUNCTION: 判斷一對(duì)象是否為數(shù)組,返回布爾值 .
SYNTAX: IsArray(name)
ARGUMENTS:
EXAMPLE: <%
strTest = "Test!"
response.write IsArray(strTest)
%>
RESULT: False
IsDate()
FUNCTION: 判斷一對(duì)象是否為日期,返回布爾值
SYNTAX: IsDate(expression)
ARGUMENTS: expression is any valid expression.
EXAMPLE: <%
strTest = "8/4/99"
response.write IsDate(strTest)
%>
RESULT: True
IsEmpty()
FUNCTION: 判斷一對(duì)象是否初始化,返回布爾值.
SYNTAX: IsEmpty(expression)
ARGUMENTS:
EXAMPLE: <%
Dim i
response.write IsEmpty(i)
%>
RESULT: True
IsNull()
FUNCTION: 判斷一對(duì)象是否為空,返回布爾值.
SYNTAX: IsNull(expression)
ARGUMENTS:
EXAMPLE: <%
Dim i
response.write IsNull(i)
%>
RESULT: False
IsNumeric()
FUNCTION: 判斷一對(duì)象是否為數(shù)字,返回布爾值.
SYNTAX: IsNumeric(expression)
ARGUMENTS:
EXAMPLE: <%
i = "345"
response.write IsNumeric(i)
%>
RESULT: True
就算數(shù)字加了引號(hào),ASP還是認(rèn)為它是數(shù)字。
IsObject()
FUNCTION: 判斷一對(duì)象是否為對(duì)象,返回布爾值.
SYNTAX: IsObject(expression)
ARGUMENTS:
EXAMPLE: <%
Set con = Server.CreateObject("ADODB.Connection")
response.write IsObject(con)
%>
RESULT: True
LBound()
FUNCTION: 返回指定數(shù)組維的最小可用下標(biāo).
SYNTAX: Lbound(arrayname [, dimension])
ARGUMENTS: ; dimension 指明要返回哪一維下界的整數(shù)。使用 1 表示第一維,2
表示第二維,以此類(lèi)推。如果省略 dimension 參數(shù),默認(rèn)值為 1.
EXAMPLE: <%
i = Array("Monday","Tuesday","Wednesday")
response.write LBound(i)
%>
RESULT: 0
LCase()
FUNCTION: 返回字符串的小寫(xiě)形式
SYNTAX: Lcase(string)
ARGUMENTS: string is any valid string expression.
EXAMPLE: <%
strTest = "This is a test!"
response.write LCase(strTest)
%>
RESULT: this is a test!
Left()
FUNCTION: 返回字符串左邊第length個(gè)字符以前的字符(含第length個(gè)字符).
SYNTAX: Left(string, length)
ARGUMENTS:
EXAMPLE: <%
strTest = "This is a test!"
response.write Left(strTest, 3)
%>
RESULT: Thi
Len()
FUNCTION: 返回字符串的長(zhǎng)度.
SYNTAX: Len(string | varName)
ARGUMENTS:
EXAMPLE: <%
strTest = "This is a test!"
response.write Len(strTest)
%>
RESULT: 15
LTrim()
FUNCTION: 去掉字符串左邊的空格.
SYNTAX: LTrim(string)
ARGUMENTS:
EXAMPLE: <%
strTest = " This is a test!"
response.write LTrim(strTest)
%>
RESULT: This is a test!
Mid()
FUNCTION: 返回特定長(zhǎng)度的字符串(從start開(kāi)始,長(zhǎng)度為length).
SYNTAX: Mid(string, start [, length])
ARGUMENTS:
EXAMPLE: <%
strTest = "This is a test! Today is Monday."
response.write Mid(strTest, 17, 5)
%>
RESULT: Today
Minute()
FUNCTION: 返回時(shí)間的分釧.
SYNTAX: Minute(time)
ARGUMENTS:
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.
EXAMPLE: <%
strTest = "This is an apple!"
response.write Replace(strTest, "apple", "orange")
%>
RESULT: This is an orange!
Right()
FUNCTION: 返回字符串右邊第length個(gè)字符以前的字符(含第length個(gè)字符).
SYNTAX: Right(string, length)
ARGUMENTS: .
EXAMPLE: <%
strTest = "This is an test!"
response.write Right(strTest, 3)
%>
RESULT: st!
Rnd()
FUNCTION: 產(chǎn)生一個(gè)隨機(jī)數(shù).
SYNTAX: Rnd [ (number) ]
ARGUMENTS:
EXAMPLE: <%
Randomize()
response.write RND()
%>
RESULT: 任何一個(gè)在0 到 1 之間的數(shù)
Round()
FUNCTION: 返回按指定位數(shù)進(jìn)行四舍五入的數(shù)值.
SYNTAX: Round(expression [, numRight])
ARGUMENTS: numRight數(shù)字表明小數(shù)點(diǎn)右邊有多少位進(jìn)行四舍五入。如果省略,則
Round 函數(shù)返回整數(shù).
EXAMPLE: <%
i = 32.45678
response.write Round(i)
%>
RESULT: 32
Rtrim()
FUNCTION: 去掉字符串右邊的字符串.
SYNTAX: Rtrim(string)
ARGUMENTS:
EXAMPLE: <%
strTest = "This is a test!! "
response.write RTrim(strTest)
%>
RESULT: This is a test!!
Second()
FUNCTION: 返回秒.
SYNTAX: Second(time)
ARGUMENTS: .
EXAMPLE: <%=Second(#12:34:28 PM#)%>
RESULT: 28
StrReverse()
FUNCTION: 反排一字符串
SYNTAX: StrReverse(string)
ARGUMENTS:
EXAMPLE: <%
strTest = "This is a test!!"
response.write StrReverse(strTest)
%>
RESULT: !!tset a si sihT
Time()
FUNCTION: 返回系統(tǒng)時(shí)間.
SYNTAX: Time()
ARGUMENTS: .
EXAMPLE: <%=Time%>
RESULT: 9:58:28 AM
Trim()
FUNCTION: 去掉字符串左右的空格.
SYNTAX: Trim(string)
ARGUMENTS: string is any valid string expression.
EXAMPLE: <%
strTest = " This is a test!! "
response.write Trim(strTest)
%>
RESULT: This is a test!!
UBound()
FUNCTION: 返回指定數(shù)組維數(shù)的最大可用下標(biāo).
SYNTAX: Ubound(arrayname [, dimension])
ARGUMENTS: ; dimension (optional) 指定返回哪一維上界的整數(shù)。1 表示第一
維,2 表示第二維,以此類(lèi)推。如果省略 dimension 參數(shù),則默認(rèn)值為 1.
EXAMPLE: <%
i = Array("Monday","Tuesday","Wednesday")
response.write UBound(i)
%>
RESULT: 2
UCase()
FUNCTION: 返回字符串的大寫(xiě)形式.
SYNTAX: UCase(string)
ARGUMENTS:
EXAMPLE: <%
strTest = "This is a test!!"
response.write UCase(strTest)
%>
RESULT: THIS IS A TEST!!
VarType()
FUNCTION: 返回指示變量子類(lèi)型的值
SYNTAX: VarType(varName)
ARGUMENTS:
EXAMPLE: <%
i = 3
response.write varType(i)
%>
RESULT: 2(數(shù)字)詳見(jiàn)"asp常數(shù)"
WeekDay()
FUNCTION: 返回在一周的第幾天.
SYNTAX: WeekDay(date [, firstdayofweek])
ARGUMENTS: .
EXAMPLE: <%
d = #8/4/99#
response.write Weekday(d)
%>
RESULT: 4(星期三)
WeekDayName()
FUNCTION: 返回一周第幾天的名字.
SYNTAX: WeekDayName(weekday [, Abb ][, firstdayofweek]])
ARGUMENTS: Abb可選。Boolean 值,指明是否縮寫(xiě)表示星期各天的名稱。如果省
略, 默認(rèn)值為 False,即不縮寫(xiě)星期各天的名稱.firstdayofweek指明星期第一天的
數(shù)值
EXAMPLE: <%
d = #8/4/99#
response.write WeekdayName(Weekday(d))
%>
RESULT: Wednesday
Year()
FUNCTION: 返回當(dāng)前的年份.
SYNTAX: Year(date)
ARGUMENTS:
EXAMPLE: <%=Year(#8/4/99#)%>
RESULT: 1999
ASP函數(shù)大全
Abs(number)
返回絕對(duì)值。
Array(arglist)
創(chuàng)建一個(gè)數(shù)組。
Asc(string)
返回字符串第一個(gè)字符的ANSI碼。
Atn(number)
返回反正弦值。
CBool (expression)
轉(zhuǎn)換成Boolean數(shù)據(jù)類(lèi)型變量。
CByte (expression)
轉(zhuǎn)換成Byte數(shù)據(jù)類(lèi)型變量。
CCur (expression)
轉(zhuǎn)換成Currency數(shù)據(jù)類(lèi)型變量。
CDate (expression)
轉(zhuǎn)換成Date數(shù)據(jù)類(lèi)型變量。
CDbl (expression)
轉(zhuǎn)換成Double數(shù)據(jù)類(lèi)型變量。
Chr(charcode)
把ANSI 碼轉(zhuǎn)換成相應(yīng)的鍵盤(pán)字符。
CInt (expression)
轉(zhuǎn)換成Integer數(shù)據(jù)類(lèi)型變量。
CLng (expression)
轉(zhuǎn)換成Long數(shù)據(jù)類(lèi)型變量。
CreateObject(servername.typename)
創(chuàng)建一個(gè)自動(dòng)對(duì)象。
CSng (expression)
轉(zhuǎn)換成Single數(shù)據(jù)類(lèi)型變量。
CStr (expression)
轉(zhuǎn)換成String數(shù)據(jù)類(lèi)型變量。
Date
根據(jù)所用的系統(tǒng)返回時(shí)間。
DateAdd(interval,number,date)
向date對(duì)象添加指定的時(shí)間間隔。其中參數(shù)interval 接受下表所示的值。
設(shè)定值
描述
yyyy
年
q
季度
m
月份
y
一年的第幾天
d
天
w
星期幾
ww
一年的第幾個(gè)星期
h
小時(shí)
m
分鐘
s
秒鐘
DateDiff(interval,date1,date2[,firstdayofweek[,firstweekofyear]])
返回兩個(gè)日期之間的間隔,關(guān)于firstdayofweek及firstweekofyear的值請(qǐng)參考下面的“日期和時(shí)間常數(shù)”一節(jié)。interval參數(shù)接受下表所示的值。
設(shè)定值
描述
yyyy
年
q
季度
m
月份
y
一年的第幾天
d
天
w
星期幾
ww
一年的第幾個(gè)星期
h
小時(shí)
m
分鐘
s
秒鐘
DatePart(interval , date[,firstdayofweek[,firstweekofyear]])
返回Date對(duì)象指定部分。關(guān)于firstdayofweek及firstweekofyear的值請(qǐng)參考下面的“日期和時(shí)間常數(shù)”一節(jié)。interval參數(shù)接受下表所示的值。
設(shè)定值
描述
yyyy
年
q
季度
m
月份
y
一年的第幾天
d
天
w
星期幾
ww
一年的第幾個(gè)星期
h
小時(shí)
m
分鐘
s
秒鐘
DateSerial(year,month,day)
轉(zhuǎn)換成Date數(shù)據(jù)子類(lèi)型變體值。
Datevalue(date)
轉(zhuǎn)換成Date數(shù)據(jù)子類(lèi)型變體值。
Day(date)
根據(jù)參數(shù)date返回該天在一個(gè)月中的號(hào)數(shù)。
Exp(number)
返回e的number次方的值。
Filter(InputStrings,value[,Include[,Compare]])
根據(jù)篩選條件創(chuàng)建一個(gè)新的數(shù)組。關(guān)于Compare的值,請(qǐng)參看后面“比較常數(shù)”一節(jié)。
Fix(number)
轉(zhuǎn)換成一個(gè)整數(shù)(對(duì)于負(fù)數(shù),只入不舍)。
FormatCurrency(Expression[,NumDigitsAfterDecimal [,IncludeLeadingDigit[,UseParensForNegativeNumbers [,GroupDigit]]]])
格式化成currency形式。關(guān)于IncludeleadingDigit,UseParensForNegativeNumbers及GroupDigit的值請(qǐng)參看后面“三態(tài)常數(shù)”一節(jié)。
FormatDateTime(Date[,NamedFormat])
對(duì)日期及時(shí)間進(jìn)行格式化輸出。關(guān)于NamedFormat的值請(qǐng)參看后面“日期格式常數(shù)”一節(jié)。
FormatNumber(Expression[,NumDigitsAfterDecimal [,IncludeLeadingDigit[,UseParensForNegativeNumbers [,GroupDigit]]]])
對(duì)數(shù)字進(jìn)行格式化。關(guān)于IncludeleadingDigit,UseParensForNegativeNumbers及GroupDigit的值請(qǐng)參看后面“三態(tài)常數(shù)”一節(jié)。
FormatPercent(Expression[,NumDigitsAfterDecimal [,IncludeLeadingDigit[,UseParensForNegativeNumbers [,GroupDigit]]]])
對(duì)百分?jǐn)?shù)進(jìn)行格式化。關(guān)于IncludeleadingDigit,UseParensForNegativeNumbers及GroupDigit的值請(qǐng)參看后面“三態(tài)常數(shù)”一節(jié)。
GetObject([pathname][,class])
從指定的文件中返回指定的動(dòng)態(tài)對(duì)象。
Hex(number)
返回?cái)?shù)number的十六進(jìn)制的值。
Hour(time)
根據(jù)參數(shù)time的值返回小時(shí)。
InputBox(prompt[,title][,default][,xpos][,ypos][,helpfile,context])
顯示一個(gè)臨時(shí)的輸入框,并且返回用戶的輸入。
InStr([start,]string1,string2[,compare])
返回字符串string2在字符串string1中第一次出現(xiàn)的位置。關(guān)于compare的值請(qǐng)參看后面的“比較常數(shù)”一節(jié)。
InStrRev(string1,string2 [start [,compare]])
返回字符串string2在字符串string1中最后出現(xiàn)的位置。關(guān)于compare的值請(qǐng)參看后面的“比較常數(shù)”一節(jié)。
Int(number)
返回一個(gè)整數(shù)(負(fù)數(shù)只舍不入)。
IsArray(varname)
確定變量是否是一個(gè)數(shù)組。
IsDate(expression)
確定表達(dá)式expression能否轉(zhuǎn)換成日期格式。
IsEmpty(varname)
確定變量是否已經(jīng)初始化了。
IsNull(expression)
確定表達(dá)式expression是否為空。
IsNumberic(expression)
確定表達(dá)式expression的結(jié)果是否是一個(gè)數(shù)。
IsObject(expression)
確定表達(dá)式expression是否是一個(gè)自動(dòng)對(duì)象。
Join(list,[,delimiter])
把一個(gè)數(shù)組中的所有子字符串連接起來(lái),連接所用的分隔符由delimiterd的值設(shè)定。
LBound(arrayname[,dimension])
返回?cái)?shù)組某維的最低界限。在當(dāng)前的VBScript版本中,該函數(shù)總是返回值0。
Lcase(string)
以小寫(xiě)字符格式化。
Left(string,length)
返回指定長(zhǎng)度的字符串string左部分。
Len(string|varname)
返回字符串string的長(zhǎng)度或變量varname的字節(jié)長(zhǎng)度。
LoadPicture(pitcurename)
載入一個(gè)圖片對(duì)象。
Log(number)
返回?cái)?shù)number的自然對(duì)數(shù)值。
Ltrim(string)
刪除字符串string左邊多余的空格。
Mid(strin,start[,length])
返回指定長(zhǎng)度的字符串string的子串。
Minute(time)
根據(jù)參數(shù)time的值返回分鐘的值。
Month(date)
返回以數(shù)字表示的月份。
MonthName(month[,abbreviate])
返回以名稱表示的月份。
MsgBox(prompt[,buttons][,title][helpfile,context])
顯示一個(gè)消息框,要求用戶選擇一個(gè)按鈕,返回能指明用戶所做選擇的值。關(guān)于button的值和返回值請(qǐng)參看后面“消息框常數(shù)”一節(jié)。
Now
根據(jù)系統(tǒng),返回當(dāng)前的日期和時(shí)間。
Oct(number)
返回?cái)?shù)number的八進(jìn)制值。
Replace(expression,find,replacewith[,start[,count[,compare]]])
用指定的子字符串replacewith替換指定的子字符串find指定的次數(shù)。關(guān)于參數(shù)compare的值請(qǐng)參看后面“比較常數(shù)”一節(jié)。
Right(string,length)
返回指定長(zhǎng)度的字符串string的右部分子串。
Rnd([number])
產(chǎn)生一個(gè)隨機(jī)數(shù)。
Round(number[,numdecimalplaces])
根據(jù)指定的十進(jìn)制位數(shù)對(duì)數(shù)number進(jìn)行四舍五入。
RTrim(string)
刪除字符串string右邊多余的空格。
ScriptEngine
返回使用的腳本語(yǔ)言的名稱。
ScriptEngineBuildVersion
返回使用的腳本引擎版本。
ScriptEngineMaorVersion
返回使用的腳本引擎的大版本號(hào)。
Second(time)
根據(jù)參數(shù)time的值返回該分的第幾秒。
Sgn(number)
返回?cái)?shù)number的正負(fù)號(hào)。
Sin(number)
返回?cái)?shù)number的正弦值。
Space(number)
用指定數(shù)量的空格創(chuàng)建字符串。
Split(expression[,delimiter[,count[,compare]]])
把一個(gè)字符串分割并轉(zhuǎn)換成數(shù)組。關(guān)于compare的值請(qǐng)參看后面“比較常數(shù)”一節(jié)。
Sqr(number)
返回?cái)?shù)number的平方根值。
StrComp(string1,string2[,compare])
字符串比較。關(guān)于compare的值請(qǐng)參看后面“比較常數(shù)”一節(jié)。
StrReverse(string1)
對(duì)字符串string1進(jìn)行倒序。
String(number,character)
用number個(gè)字符character創(chuàng)建字符串。
Tan(number)
返回?cái)?shù)number的正切。
Time
根據(jù)系統(tǒng)返回當(dāng)前時(shí)間。
TimeSerial(hour,minute,second)
返回Date變量體。
Timevalue(time)
返回包含時(shí)間的Date變量體。
Trim(string)
刪除字符串string兩邊的多余空格。
TypeName(varname)
返回子類(lèi)型的名稱。關(guān)于返回值請(qǐng)參看后面“變量類(lèi)型常數(shù)”一節(jié)。
UBound(arrayname[,dimension])
返回?cái)?shù)組某維的上邊界。缺省維數(shù)時(shí),為第一維。
Ucase(string)
用大寫(xiě)字母格式格式化字符串string。
VarType(varname)
返回子類(lèi)型的值。關(guān)于返回值請(qǐng)參看后面“變量類(lèi)型常數(shù)”一節(jié)。
Weekday(date,[firstdayofweek])
用數(shù)字形式返回星期幾。關(guān)于參數(shù)firstdayofweek的值請(qǐng)參看后面“變量類(lèi)型常數(shù)”一節(jié)。
WeekDayName(weekday,abbreviate,firstdayofweek)
用名稱形式返回星期幾。關(guān)于參數(shù)firstdayofweek的值請(qǐng)參看后面“變量類(lèi)型常數(shù)”一節(jié)。
Year(date)
根據(jù)參數(shù)date返回年份。
asp 中處理文件上傳以及刪除時(shí)常用的自定義函數(shù):
<%
’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’
’所有自定義的VBS函數(shù)
’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’
function DeleteFile(Filename) ’刪除文件
if Filename<>"" then
Set fso = server.CreateObject("Scripting.FileSystemObject")
if fso.FileExists(Filename) then
fso.DeleteFile Filename
end if
set fso = nothing
end if
end function
’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’
function CreateDIR(byval LocalPath) ’建立目錄的程序,如果有多級(jí)目錄,則一級(jí)一級(jí)的創(chuàng)建
on error resume next
LocalPath = replace(LocalPath,"\","/")
set FileObject = server.createobject("Scripting.FileSystemObject")
patharr = split(LocalPath,"/")
path_level = ubound(patharr)
for i = 0 to path_level
if i=0 then pathtmp=patharr(0) & "/" else pathtmp = pathtmp & patharr(i) & "/"
cpath = left(pathtmp,len(pathtmp)-1)
if not FileObject.FolderExists(cpath) then FileObject.CreateFolder cpath
next
set FileObject = nothing
if err.number<>0 then
CreateDIR = false
err.Clear
else
CreateDIR = true
end if
end function
’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’
function SaveRandFileName(byval szFilename) ’根據(jù)原文件名生成新的隨機(jī)文件名
randomize
’ranNum=int(90000*rnd)+10000
’if month(now)<10 then c_month="0" & month(now) else c_month=month(now)
’if day(now)<10 then c_day="0" & day(now) else c_day=day(now)
’if hour(now)<10 then c_hour="0" & hour(now) else c_hour=hour(now)
’if minute(now)<10 then c_minute="0" & minute(now) else c_minute=minute(now)
’if second(now)<10 then c_second="0" & second(now) else c_second=minute(now)
fileExt_a=split(szFilename,".")
fileExt=lcase(fileExt_a(ubound(fileExt_a)))
SaveRandFileName=replace(replace(replace(now,":",""),"-","")," ","")&int(10*rnd)&"."&fileExt
’GenerateRandomFileName = year(now)&c_month&c_day&c_hour&c_minute&c_second&"_"&ranNum&"."&fileExt
end function
’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’
function jaron_replacer(strContent,start_string,end_string,replace_string)
’CMS替換函數(shù):源字符串,前部分,后部分,替換成的字符
’返回被替換后的字符串
jaron_replacer = replace(strContent,mid(strContent,instr(strContent,start_string),instr(strContent,end_string)+len(end_string)-1),replace_string)
end function
’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’
function replaceplus(strContent,start_string,end_string,replace_string)
’文檔中,將所有開(kāi)始,結(jié)束之間的所有字符刪除
on error resume next
MARKCOUNTS = ubound(split(strContent,start_string))
PRESTRING = strContent
for i=0 to MARKCOUNTS
STARTMARK=instr(1,PRESTRING,start_string,1)
if STARTMARK=0 then exit for
COMPMARK=instr(1,PRESTRING,end_string,1) + len(end_string)
VerString=mid(PRESTRING,STARTMARK,COMPMARK - STARTMARK)
PRESTRING = replace(PRESTRING,VerString,replace_string)
next
replaceplus = PRESTRING
if err.number<>0 then err.Clear
end function
’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’
%>
檢測(cè)一個(gè)字符串在另一個(gè)字符串當(dāng)中出現(xiàn)幾次的函數(shù)
Function CheckTheChar(TheChar,TheString)
’TheChar="要檢測(cè)的字符串"
’TheString="待檢測(cè)的字符串"
if inStr(TheString,TheChar) then
for n =1 to Len(TheString)
if Mid(TheString,n,Len(TheChar))=TheChar then
CheckTheChar=CheckTheChar+1
End if
Next
CheckTheChar="這個(gè)字符"&CheckTheChar&"次"
else
CheckTheChar="0次"
end if
End Function
example:
Response.write CheckTheChar("大家","a224大家4a434a4大家654arewr4a4a" )
半角<=>全角互轉(zhuǎn)函數(shù)[JS版 VBS版]
<script>
/*
****************************
* 半角<=>全角 *
* [NB聯(lián)盟] *
* Writer YuPing *
****************************
* 參數(shù)說(shuō)明:
* str:要轉(zhuǎn)換的字符串
* flag:標(biāo)記,為0時(shí)半轉(zhuǎn)全,為非0時(shí)全轉(zhuǎn)半
* 返回值類(lèi)型:字符串
****************************
*/
function DBC2SBC(str,flag) {
var i;
var result=’’;
if (str.length<=0) {alert(’字符串參數(shù)出錯(cuò)’);return false;}
for(i=0;i<str.length;i++)
{ str1=str.charCodeAt(i);
if(str1<125&&!flag)
result+=String.fromCharCode(str.charCodeAt(i)+65248);
else
result+=String.fromCharCode(str.charCodeAt(i)-65248);
}
return result;
}
//示例:
alert(DBC2SBC("AAabc",0));
document.write(DBC2SBC("abcdefg",0))
</script>
<input type=text value="abcdefg" id=txt><input type=button value="變" onclick=txt.value=DBC2SBC(txt.value)>
<script language="vbscript">
’****************************
’* 半角<=>全角 *
’* [NB聯(lián)盟] *
’* Writer YuPing *
’****************************
’* 參數(shù)說(shuō)明:
’* str:要轉(zhuǎn)換的字符串
’* flag:標(biāo)記,為0時(shí)半轉(zhuǎn)全,為非0時(shí)全轉(zhuǎn)半
’* 返回值類(lèi)型:字符串
’****************************
function DBC2SBC(str,flag)
dim i
if len(str)<=0 then
msgbox ’字符串參數(shù)出錯(cuò)’
exit function
end if
for i=1 to len(str)
str1=asc(mid(str,i,1))
if str1>0 and str1<=125 and not flag then
dbc2sbc=dbc2sbc&chr(asc(mid(str,i,1))-23680)
else
dbc2sbc=dbc2sbc&chr(asc(mid(str,i,1))+23680)
end if
next
end function
’示例:
alert(dbc2sbc("AB",1))
</script>
截取固定字?jǐn)?shù)
<SCRIPT RUNAT=SERVER LANGUAGE=VBSCRIPT>
function DoTrimProperly(str, nNamedFormat, properly, pointed, points)
dim strRet
strRet = Server.HTMLEncode(str)
strRet = replace(strRet, vbcrlf,"")
strRet = replace(strRet, vbtab,"")
If (LEN(strRet) > nNamedFormat) Then
strRet = LEFT(strRet, nNamedFormat)
If (properly = 1) Then
Dim TempArray
TempArray = split(strRet, " ")
Dim n
strRet = ""
for n = 0 to Ubound(TempArray) - 1
strRet = strRet & " " & TempArray(n)
next
End If
If (pointed = 1) Then
strRet = strRet & points
End If
End If
DoTrimProperly = strRet
End Function
</SCRIPT>
列如:
<% =(DoTrimProperly((rsh.Fields.Item("n_title").value), 10, 0, 1, "...")) %>
檢驗(yàn)表單
<script language="javascript">
<!--
function isEmpty(s)
{
return ((s == null) || (s.length == 0))
}
function isWhitespace (s)
{
var whitespace = " \t\n\r";
var i;
// 以下代碼判斷是否有空字符
for (i = 0; i < s.length; i++)
{
var c = s.charAt(i);
if (whitespace.indexOf(c) >= 0)
{
return true;
}
}
return false;
}
function isCharsInBag (s, bag)
{
var i;
for (i = 0; i < s.length; i++)
{
var c = s.charAt(i);
if (bag.indexOf(c) == -1) return false;
}
return true;
}
function isEmail (s)
{
//判斷Email是否為空
if (isEmpty(s))
{
window.alert("輸入的E-mail地址不能為空,請(qǐng)輸入!");
return false;
}
//判斷Email中是否包含空格
if (isWhitespace(s))
{
window.alert("輸入的E-mail地址中不能包含空格符,請(qǐng)重新輸入!");
return false;
}
//判斷Email地址長(zhǎng)度
var i = 1;
var len = s.length;
if (len > 100)
{
window.alert("Email地址長(zhǎng)度不能超過(guò)100位!");
return false;
}
pos1 = s.indexOf("@");
pos2 = s.indexOf(".");
pos3 = s.lastIndexOf("@");
pos4 = s.lastIndexOf(".");
//判斷Email地址中是否包含符號(hào) "@"
if ((pos1 <= 0)||(pos1 == len)||(pos2 <= 0)||(pos2 == len))
{
window.alert("請(qǐng)輸入有效的E-mail地址!");
return false;
}
else
{
if( (pos1 == pos2 - 1) || (pos1 == pos2 + 1)
|| ( pos1 != pos3 ) //find two @
|| ( pos4 < pos3 ) ) //. should behind the "@"
{
window.alert("請(qǐng)輸入有效的E-mail地址!");
return false;
}
}
if ( !isCharsInBag( s, "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789.-_@"))
{
window.alert("email地址中只能包含字符ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789.-_@\n" + "請(qǐng)重新輸入" );
return false;
}
//判斷是否包含有效的字符
/*
var badChar = "><,[]{}?/+=|\\"\":;!#$%^&()`";
if ( isCharsInBag( s, badChar))
{
alert("請(qǐng)不要在email地址中輸入字符 " + badChar + "\n" );
alert("請(qǐng)重新輸入" );
return false;
}
*/
return true;
}
function checkdata() {
if (document.form1.Email.value=="") {
window.alert ("請(qǐng)輸入您的E-mail地址 !")
return false
}
if ( !isEmail(document.form1.Email.value) )
return false
if (document.form1.Pass.value=="") {
window.alert ("請(qǐng)輸入您的密碼 !")
return false
}
if (document.form1.Pass.value.length<5) {
window.alert ("您的密碼數(shù)必須大于4位 !")
return false
}
if (document.form1.Pass.value.length>10) {
window.alert ("您的密碼數(shù)必須小于10位 !")
return false
}
if (document.form1.Comfpass.value=="") {
window.alert ("請(qǐng)輸入您的確認(rèn)密碼 !")
return false
}
if (document.form1.Pass.value!=document.form1. Comfpass.value) {
window.alert ("您的密碼不一致 !")
return false
}
if (document.form1.Pass_question.value=="") {
window.alert ("請(qǐng)輸入您取回密碼的問(wèn)題 !")
return false
}
if (document.form1. Pass_answer.value=="") {
window.alert ("請(qǐng)輸入您取回密碼的答案!")
return false
}
if (document.form1.Name.value=="") {
window.alert ("請(qǐng)輸入您的真實(shí)姓名 !")
return false
}
if (document.form1.City.value=="") {
window.alert ("請(qǐng)輸入所在城市 !")
return false
}
if (document.form1.Address.value=="") {
window.alert ("請(qǐng)輸入您的詳細(xì)地址 !")
return false
}
if (document.form1.Zip.value=="") {
window.alert ("請(qǐng)輸入您的郵編 !")
return false
}
if (document.form1.Phone.value=="") {
window.alert ("請(qǐng)輸入您的電話號(hào)碼 !")
return false
}
if (document.form1.fax.value=="") {
window.alert ("請(qǐng)輸入您的傳真號(hào)碼 !")
return false
}
if (document.form1.mobil.value=="") {
window.alert ("請(qǐng)輸入您的手機(jī)號(hào)碼 !")
return false
}
return true
}
//-->
</script>
例如:
<form name="form1" method="POST" action="/cinfocheck.asp" onSubmit="return checkdata()">
轉(zhuǎn)換空格和回車(chē)
<SCRIPT RUNAT=SERVER LANGUAGE=VBSCRIPT>
function DoWhiteSpace(str)
DoWhiteSpace = Replace((Replace(str, vbCrlf, "<br>")), chr(32)&chr(32), " ")
End Function
</SCRIPT>
例子:N_Content=DoWhiteSpace(Request.Form("N_Content"))
按要求彈窗口轉(zhuǎn)向
if (confirm("到 a.htm 嗎?"))
{
window.location.href="a.htm";
}
else
{
window.location.href="b.htm";
}
按鈕倒記時(shí)效果
<script language="javascript">
var secs = 9;
var wait = secs * 1000;
document.form1.rulesubmit.value = "同 意(" + secs + ")";
document.form1.rulesubmit.disabled = true;
for(i = 1; i <= secs; i++) {
window.setTimeout("update(" + i + ")", i * 1000);
}
window.setTimeout("timer()", wait);
function update(num, value) { , ;
if(num == (wait/1000)) {
document.form1.rulesubmit.value = "同 意";
} else {
printnr = (wait / 1000)-num;
document.form1.rulesubmit.value = "同 意(" + printnr + ")";
}
}
function timer() {
document.form1.rulesubmit.disabled = false;
document.form1.rulesubmit.value = "同 意";
}
</script>
<form name="form1" method="post" action="">
<input type="submit" name="rulesubmit" value="同 意" style="height: 23px">
</form>
全選和取消全選
<SCRIPT language="javascript">
function checkAll(bCheck)
{
var arr = document.all.chk;
for(var i=0; i<arr.length; i++)
{
if(!arr[i].disabled == true)
arr[i].checked = bCheck;
}
}
</SCRIPT>
<INPUT TYPE="checkbox" NAME="all" onclick="checkAll(this.checked)"><p>
<INPUT TYPE="checkbox" NAME="chk">
<INPUT TYPE="checkbox" NAME="chk">
<INPUT TYPE="checkbox" NAME="chk" disabled>
<INPUT TYPE="checkbox" NAME="chk">
<INPUT TYPE="checkbox" NAME="chk">
在當(dāng)前位置加入指定字符
<HTML>
<HEAD>
<SCRIPT>
function insertAtCaret (textEl, text) {
textEl.focus();
document.selection.createRange().text=text;
}
</SCRIPT>
</HEAD>
<BODY>
<FORM NAME="aForm">
<TEXTAREA NAME="aTextArea" ROWS="5" COLS="80" WRAP="soft">測(cè)試測(cè)試測(cè)試測(cè)試測(cè)
試測(cè)試
</TEXTAREA>
<BR>
<INPUT TYPE="text" NAME="aText" SIZE="80" value="要插入的文字">
<BR>
<INPUT TYPE="button" value="insert"
onCLICK="insertAtCaret(this.form.aTextArea,this.form.aText.value);">
</FORM>
</BODY>
</HTML>
找到2個(gè)tag之間的內(nèi)容
<%
Function RegGetString(expression)
Dim reg
Set reg = New RegExp
reg.IgnoreCase = True
reg.Global = True
reg.Pattern = "(.*?)<!--A-->(.*?)<!--B-->(.*?)"
RegGetString= reg.Replace(expression,"$1<hello>$2")
Set reg =nothing
End Function
%>
<% = RegGetString("標(biāo)記外1<!--A-->記錄一<!--B-->標(biāo)記外2<!--A-->記錄二<!--B-->標(biāo)記外3") %>
ASP語(yǔ)法速查表
作者:佚名 文章來(lái)源:不詳 點(diǎn)擊數(shù):1302 更新時(shí)間:2004-10-16
VBScript 函數(shù)
功能說(shuō)明
例子
Abs (數(shù)值) 絕對(duì)值。一個(gè)數(shù)字的絕對(duì)值是它的正值?兆址 (null) 的絕對(duì)值,也是空字符串。未初始化的變數(shù),其絕對(duì)為 0 例子:ABS(-2000)
結(jié)果:2000
Array (以逗點(diǎn)分隔的數(shù)組元素) Array 函數(shù)傳回?cái)?shù)組元素的值。 例子:
A=Array(1,2,3)
B=A(2)
結(jié)果: 2
說(shuō)明:變量B為A數(shù)組的第二個(gè)元素的值。
Asc (字符串) 將字符串的第一字母轉(zhuǎn)換成 ANSI (美國(guó)國(guó)家標(biāo)準(zhǔn)符號(hào))字碼。 例子:Asc(”Internet”)
結(jié)果:73
說(shuō)明:顯示第一字母 I 的 ANSI 字碼。
CBool(表達(dá)式) 轉(zhuǎn)換成布爾邏輯值變量型態(tài)(True 或False ) 例子:CBool(1+2)
結(jié)果:True
CDate (日期表達(dá)式) 換成日期變量型態(tài)。可先使用 IsDate 函數(shù)判斷是否可以轉(zhuǎn)換成日 期。 例子: CDate (now( )+2)
結(jié)果:2000/5/28 10:30:59
CDbl(表達(dá)式) 轉(zhuǎn)換成DOUBLE變量型態(tài)。
Chr ( ANSI 字碼) 將ASCII 字碼轉(zhuǎn)換成字符。 例子: Chr ( 72 )
結(jié)果: H
CInt (表達(dá)式) 轉(zhuǎn)換成整數(shù)變量型態(tài)。 例子: CInt ("3.12")
結(jié)果: 3
CLng (表達(dá)式) 轉(zhuǎn)換成LONG 變量型態(tài)。
CSng (表達(dá)式) 轉(zhuǎn)換成SINGLE 變量型態(tài)。
CStr (表達(dá)式) 轉(zhuǎn)換成字符串變量型態(tài)。
Date ( )top 傳回系統(tǒng)的日期。 例子: Date
結(jié)果: 2000/5/13
DateAdd ( I , N , D ) 將一個(gè)日期加上一段期間后的日期。 I :設(shè)定一個(gè)日期( Date )所加上的一段期間的單位。譬如 interval="d" 表示 N的單位為日。 I的設(shè)定值如下:
yyyy Year 年
q Quarter 季
m Month 月
d Day 日
w Weekday 星期
h Hour 時(shí)
n Minute 分
s Second 秒
N :數(shù)值表達(dá)式,設(shè)定一個(gè)日期所加上的一段期間,可為正值或負(fù)值,正值表示加(結(jié)果為 >date 以后的日期),負(fù)值表示減(結(jié)果為 >date 以前的日期)。
D :待加減的日期。 例子: DateAdd ( "m" , 1 , "31-Jan-98")
結(jié)果: 28-Feb-98
說(shuō)明:將日期 31-Jan-98 加上一個(gè)月,結(jié)果為 28-Feb-98 而非 31-Fe-98 。
例子: DateAdd ( "d" , 20 , "30-Jan-99")
結(jié)果: 1999/2/9
說(shuō)明:將一個(gè)日期 30-Jan-99 加上 20 天后的日期。
DateDiff (I , D1 , D2[,FW[,FY]]) 計(jì)算兩個(gè)日期之間的期間。
I :設(shè)定兩個(gè)日期之間的期間計(jì)算之單位。譬如 >I="m" 表示計(jì)算的單位為月。 >I 的設(shè)定值如:
yyyy > Year 年
q Quarter 季
m Month 月
d Day 日
w Weekday 星期
h Hour 時(shí)
m Minute 分
s Second 秒
D1 ,D2:計(jì)算期間的兩個(gè)日期表達(dá)式,若 >date1 較早,則兩個(gè)日期之間的期間結(jié)果為正值;若 >date2 較早, 則結(jié)果為負(fù)值。
FW :設(shè)定每周第一天為星期幾, 若未設(shè)定表示為星期天。 >FW 的設(shè)定值如下:
0 使用 >API 的設(shè)定值。
1 星期天
2 星期一
3 星期二
4 星期三
5 星期四
6 星期五
7 星期六
FY :設(shè)定一年的第一周, 若未設(shè)定則表示一月一日那一周為一年的第一周。 >FY 的設(shè)定值如下:
0 使用 >API 的設(shè)定值。
1 一月一日那一周為一年的第一周
2 至少包括四天的第一周為一年的第一周
3 包括七天的第一周為一年的第一周 例子: DateDiff ("d","25-Mar-99 ","30-Jun-99 ")
結(jié)果: 97
說(shuō)明:顯示兩個(gè)日期之間的期間為 97 天。
DatePart (I,D,[,FW[,FY]]) 傳回一個(gè)日期的之部份。
>I :設(shè)定傳回那一部份。譬如 >I="d" 表示傳回 部份為日。 >I 的設(shè)定值如下:
yyyy Year 年
q Quarter 季
m Month 月
d Day 日
w Weekday 星期
h Hour 時(shí)
m Minute 分
s Second 秒
D :待計(jì)算的日期。
>FW :設(shè)定每周第一天為星期幾, 若未設(shè)定則表示為星期天。 >FW 的設(shè)定值如下:
0 使用 >API 的設(shè)定值。
1 星期天
2 星期一>3 星期二
4 星期三
5 星期四
6 星期五
7 星期六
FY :設(shè)定一年的第一周, 若未設(shè)定則表示一月一日那一周為一年的第一周。 >FY 的設(shè)定值如下:
0 使用 >API 的設(shè)定值。
1 一月一日那一周為一年的第一周
2 至少包括四天的第一周為一年的第一周
3 包括七天的第一周為一年的第一周 例子: DatePart ("m","25-Mar-99 ")
結(jié)果: 3
說(shuō)明:顯示傳回一個(gè)日期 的月部份。
Dateserial (year,month,day) 轉(zhuǎn)換(year,month,day) 成日期變量型態(tài)。 例子: DateSerial (99,10,1)
結(jié)果: 1999/10/1
Datevalue ( 日期的字符串或表達(dá)式 ) 轉(zhuǎn)換成日期變量型態(tài),日期從 January 1,100 到 December 31,9999 。格式為 month,day,and year 或 month/day/year 。譬如: December 30,1999 、 Dec 30,1999 、 12/30/1999 、 12/30/99 例子: Datevalue ("January 1,2002 ")
結(jié)果: 2002/1/1
Day( 日期的字符串或表達(dá)式 ) 傳回日期的「日」部份。 例子: Day(" 12/1/1999 ")
結(jié)果: 1
Fix( 表達(dá)式 )top 轉(zhuǎn)換字符串成整數(shù)數(shù)字型態(tài)。與 Int 函數(shù)相同。若為 null 時(shí)傳回 null 。
Int (number) 與 Fix(number) 的差別在負(fù)數(shù)。如 Int (-5.6)=-6 , Fix(-5.6)=-5 。 例子: Fix(5.6)
結(jié)果: 5
Hex( 表達(dá)式 )top 傳回?cái)?shù)值的十六進(jìn)制值。若表達(dá)式為 null 時(shí) Hex( 表達(dá)式 )=null ,若表達(dá)式 =Empty 時(shí) Hex( 表達(dá)式 )=0 。 16 進(jìn)位可以加「 &H 」表示,譬如 16 進(jìn)位 &H10 表示十進(jìn)制的 16 。 例子: Hex(30)
結(jié)果: 1E
Hour( 時(shí)間的字符串或表達(dá)式 ) 傳回時(shí)間的「小時(shí)」部份。 例子: Hour("12:30:54 ")
結(jié)果: 12
InStr ([start,]string1,string2[,compare]) top 將一 個(gè) 字符串由左 而右與另一個(gè)比較,傳回第一個(gè)相同的位置。
start 為從第幾個(gè)字比較起,若省略 start 則從第一個(gè)字比較起, string1 為待尋找的字符串表達(dá)式, string2 為 待比較的字符串表達(dá)式, compare 為比較的方法, compare=0 表二進(jìn)制比較法, compare=1 表文字比較法,若省略 compare 則為預(yù)設(shè)的二進(jìn)制比較法。 例子: InStr("abc123def123","12")
結(jié)果: 4
InstrRev ([start,]string1,string2[,compare]) 將一 個(gè) 字符串 由右而左與另一個(gè)比較,傳回第一個(gè)相同的位置。
start 為從第幾個(gè)字比較起,若省略 start 則從第一個(gè)字比較起, string1 為待尋找的字符串表達(dá)式, string2 為 待比較的字符串表達(dá)式, compare 為比較的方法, compare=0 表二進(jìn)制比較法, compare=1 表文字比較法,若省略 compare 則為預(yù)設(shè)的二進(jìn)制比較法。 例子: InstrRev ("abc123def123","12")
結(jié)果: 10
Int ( 表達(dá)式 ) 傳回一個(gè)數(shù)值的整數(shù)部份。與 Fix 函數(shù)相同。 例子: Int (5.6)
結(jié)果: 5
IsArray ( 變數(shù) ) 測(cè)試變量是 (True) 否 (False) 是一個(gè)數(shù)組。 例子: IsArray (3)
結(jié)果: False
說(shuō)明:不是一個(gè)數(shù)組。
IsDate ( 日期或字符串的表達(dá)式 ) 是否可以轉(zhuǎn)換成日期。日, 期從 January 1,100 A.D. 到 December 31,9999 A.D 。 例子: IsDate ("December 31,1999 ")
結(jié)果: True
說(shuō)明:可以轉(zhuǎn)換成日期。
IsEmpty ( 變數(shù) ) 測(cè)試變量是 (True) 否 (False) 已經(jīng)被初始化 例子: IsEmpty (a)
結(jié)果: True
IsNull ( 變數(shù) ) 測(cè)試變數(shù)是 (True) 否 (False) 不是有效的數(shù)據(jù)。 例子: IsNull ("")
結(jié)果: False
說(shuō)明:是有效的數(shù)據(jù)。
IsNumeric ( 表達(dá)式 ) 是 (True) 否 (False) 是數(shù)字。 例子: IsNumeric ("abc123")
結(jié)果: False
說(shuō)明:不是數(shù)字。
LCase ( 字符串表達(dá)式 ) top 轉(zhuǎn)換字符串成小寫(xiě)。將大寫(xiě)字母的部份轉(zhuǎn)換成小寫(xiě)。字符串其余的部份不變。 例子: LCase ("ABC123")
結(jié)果: abc123
Left( 字符串表達(dá)式 ,length) 取字符串左邊的幾個(gè)字。 length 為取個(gè)字。 Len 函數(shù)可得知字符串的長(zhǎng)度。 例子: Left("ABC123",3)
結(jié)果: ABC
Len( 字符串表達(dá)式 變量 ) 取得字符串的長(zhǎng)度。 例子: Len("ABC123")
結(jié)果: 6
LTrim ( 字符串表達(dá)式 ) 除去字符串左邊的空白字。 RTrim 除去字符串右邊的空白字, Trim 函數(shù)除去字符串左右兩邊的空白字。 例子: LTrim ("456+" abc ")
結(jié)果: 456abc123
Mid( 字符串表達(dá)式 ,start[,length]) top 取字符串中的幾個(gè)字。 start 為從第幾個(gè) 字取起, length 為取幾個(gè)字, 若略 length 則從 start 取到最右底。由Len 函數(shù)可得知字符串的長(zhǎng)度。 例子: Mid("abc123",2,3)
結(jié)果: c12
Minute( 日期的字符串或表達(dá)式 ) 傳回時(shí)間的「分鐘」部份。 例子: Minute("12:30:54")
結(jié)果:30
Month(日期的字符串或表達(dá)式) 傳回日期的「月」部份。 例子:Month("12/1/2001")
結(jié)果:12
MonthName(month[,abbreviate]) 傳回月的名稱。
month :待傳回月名稱的數(shù)字 1~12 。譬如, 1 代表一月, 7 代表七月。
abbreviate: 是 (True) 否 (False) 為縮寫(xiě),譬如 March ,縮寫(xiě)為 Mar 。默認(rèn)值為 False 。中文的月名稱無(wú)縮寫(xiě)。 例子: MonthName (7)
結(jié)果:七月
Now() 傳回系統(tǒng)的日期時(shí)間。 例子: Now()
結(jié)果: 2001/12/30 10:35:59 AM
Oct() 傳回?cái)?shù)值的八進(jìn)位值。八進(jìn)位可以加「 &O 」表示,譬如八進(jìn)位 &O10 表示十進(jìn)制的 8 。 例子: Oct(10)
結(jié)果: 12
Replace( 字符串表達(dá)式,findnreplacewith[,start[,count[,compare]]]) 將一個(gè)字符串取代 部份字。尋找待取代的原字符串 (find) , 若找到則被取代為新字符串 (replacewith) 。
find :待尋找取代的原字符串。
replacewith :取代后的字。
start :從第幾個(gè)字開(kāi)始尋找取代, 若未設(shè)定則由第一個(gè)字開(kāi)始尋找。
count :取代的次數(shù)。 若未設(shè)定則所有尋找到的字符串取代字符 串全部被取代。
compare :尋找比較的方法, compare=0 表示二進(jìn)制比較法, compare=1 表文字比較法, compare =2 表根據(jù)比較的 數(shù)據(jù)型態(tài)而定,若省略 compare 則為預(yù)設(shè)的二進(jìn)制比較法。 例子: Replace("ABCD123ABC","AB","ab")
結(jié)果: abCD123abC
Right( 字符串表達(dá)式 ,length) 取字符串右邊的幾個(gè)字, length 為取幾個(gè)字。 Len 函數(shù)可得知字符串的長(zhǎng)度。 例子: Right("ABC123",3)
結(jié)果: 123
Rnd [(number)] 0~1 的 隨機(jī)隨機(jī)數(shù)值。 number 是任何有效的數(shù)值表達(dá)式。若 number 小于 0 表示每次得到相同的 隨機(jī)隨機(jī)數(shù)值。 number 大于 0 或未提供時(shí)表示依序得到下一個(gè) 隨機(jī)隨機(jī)數(shù)值。 >number=0 表示得到最近產(chǎn)生的 隨機(jī)隨機(jī)數(shù)值。為了避免得到相同的隨機(jī)隨機(jī)數(shù)順序,可以于 Rnd 函數(shù)前加 Randomize 。 例子: Rnd
結(jié)果: 0.498498
Round( 數(shù)值表達(dá)式 [,D]) 四舍五入。
D :為四舍五入到第幾位小數(shù),若省略則四舍五入到整數(shù)。 例子: Round(30635,1)
結(jié)果: 3.6
RTrim ( 字符串表達(dá)式 ) 除去字符串右邊的空白字。 LTrim 除去字符串左邊的空白字, Trim 函數(shù)除去字符串左右兩邊的空白字。 例子: RTrim ("abc123 ")+"456"
結(jié)果: abc123456
Second( 時(shí)間的字符串或表達(dá)式 )top 傳回時(shí)間的「秒」部份。 例子:Second("12:30:54")
結(jié)果:54
Space( 重復(fù)次數(shù) ) 得到重復(fù)相同的空白字符串。 例子: A"+Space (5)+"B
結(jié)果: A B
說(shuō)明: A 和 B 中間加入五個(gè)空白字。
String( 重復(fù)次數(shù),待重復(fù)的字 ) 得到重復(fù)相同的字符串。 例子: String(5,71)
結(jié)果: GGGGG
StrReverse (String(10,71)) 將一個(gè)字符串順序顛倒。 例子: StrReverse ("ABC")
結(jié)果: CBA
Time() 傳回系統(tǒng)的時(shí)間。 例子: Time
結(jié)果: 10:35:59 PM
TimeSerial (hour,minute,second) 轉(zhuǎn)換指定的 ( hour,minute,second) 成時(shí)間 變量型態(tài)。 例子: TimeSerial (10,31,59)
結(jié)果: 10:31:59
Timevalue ( 日期的字符串或表達(dá)式 ) 轉(zhuǎn)換 成時(shí)間變量型態(tài)。日期的字符串或表達(dá)式從 0:00:00(12:00:00 A.M.) 到 23:59:59(11:59:59 P.M.) 。 例子: Timevalue (" 11:59:59 ")
結(jié)果: 11:59:59
Trim( 字符串表達(dá)式 ) 除去字符串左右兩邊的空白字。 例子: Trim(" abc123 ")
結(jié)果: abc123
UCase ()top 轉(zhuǎn)換字符串成大寫(xiě)。將小寫(xiě)字母的部份轉(zhuǎn)換成大寫(xiě),字符串其余部份不變。 例子: UCase ("abc123")
結(jié)果: ABC123
VarType ( 變數(shù) ) 傳回一個(gè)變量類(lèi)型。與 TypeName 函數(shù)相同, VarType 傳回變量類(lèi)型的代碼, TypeName 傳回變量類(lèi)型的名稱。 例子: VarType ( "I love you!")
結(jié)果: 8
Weekday( 日期表達(dá)式 ,[FW]) 傳回星期幾的數(shù)字。
FW :設(shè)定一周的第一天是星期幾。若 省略則表 1( 星期日 ) 。
Firstdayfweek 設(shè)定值為: 1( 星期日 ),2( 星期一 ),3( 星期二 ),4( 星期三 ),5( 星期四 ),6( 星期五 ),7( 星期六 ) 。 例子: Weekday(" 1/1/2000")
結(jié)果: 7
WeekDayName (W,A,FW) 傳回星期幾的名稱。
W :是 (True) 否 (False) 為縮寫(xiě)。譬如 March ,縮寫(xiě)為 Mar 。預(yù)設(shè)為 False 。中文的星期幾名稱無(wú)縮寫(xiě)。
FW :設(shè)定一周的第一天是星期幾。 若省略表 1( 星期日 ) 。設(shè)定待傳回星期幾的名稱,為一周中的第幾天。
A : 1( 星期日 ),2( 星期一 ),3( 星期二 ),4( 星期三 ),5( 星期四 ),6( 星期五 ),7( 星期六 ) 。 例子: WeekDayName ("1/1/2000")
結(jié)果:星期六
Year() 傳回日期的「年」部份。 例子: Year(" 12/1/2000 ")
結(jié)果: 2000
ASP函數(shù)詳解(1)
http://www.yzcc.com/2005/1-16/09311124554.html
Array()
FUNCTION: 返回一個(gè)數(shù)組
SYNTAX: Array(list)
ARGUMENTS: 字符,數(shù)字均可
EXAMPLE: <%
Dim myArray()
For i = 1 to 7
Redim Preserve myArray(i)
myArray(i) = WeekdayName(i)
Next
%>
RESULT: 建立了一個(gè)包含7個(gè)元素的數(shù)組myArray
myArray("Sunday","Monday", ... ... "Saturday")
CInt()
FUNCTION: 將一個(gè)表達(dá)式轉(zhuǎn)化為數(shù)字類(lèi)型
SYNTAX: CInt(expression)
ARGUMENTS: 任何有效的字符均可
EXAMPLE: <%
f = "234"
response.write cINT(f) + 2
%>
RESULT: 236
轉(zhuǎn)化字符"234"為數(shù)字"234",如果字符串為空,則返回0值
CreateObject()
FUNCTION: 建立和返回一個(gè)已注冊(cè)的ACTIVEX組件的實(shí)例。
SYNTAX: CreateObject(objName)
ARGUMENTS: objName 是任何一個(gè)有效、已注冊(cè)的ACTIVEX組件的名字.
EXAMPLE: <%
Set con = Server.CreateObject("ADODB.Connection")
%>
RESULT:
CStr()
FUNCTION: 轉(zhuǎn)化一個(gè)表達(dá)式為字符串.
SYNTAX: CStr(expression)
ARGUMENTS: expression 是任何有效的表達(dá)式。
EXAMPLE: <%
s = 3 + 2
response.write "The result is: " & cStr(s)
%>
RESULT: 轉(zhuǎn)化數(shù)字“5”為字符“5”。
Date()
FUNCTION: 返回當(dāng)前系統(tǒng)日期.
SYNTAX: Date()
ARGUMENTS: None.
EXAMPLE: <%=Date%>
RESULT: 8/4/99
DateAdd()
FUNCTION: 返回一個(gè)被改變了的日期。
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.
EXAMPLE: <%
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
%>
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: 返回兩個(gè)日期之間的差值 。
SYNTAX: DateDiff(timeinterval,date1,date2 [, firstdayofweek [, firstweekofyear]])
ARGUMENTS: timeinterval 表示相隔時(shí)間的類(lèi)型,如“M“表示“月”。
EXAMPLE: <%
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: 返回一個(gè)月的第幾日 .
SYNTAX: Day(date)
ARGUMENTS: date 是任何有效的日期。
EXAMPLE: <%=Day(#8/4/99#)%>
RESULT: 4
FormatCurrency()
FUNCTION: 返回表達(dá)式,此表達(dá)式已被格式化為貨幣值
SYNTAX: FormatCurrency(Expression [, Digit [, LeadingDigit [, Paren [, GroupDigit]]]])
ARGUMENTS: Digit 指示小數(shù)點(diǎn)右側(cè)顯示位數(shù)的數(shù)值。默認(rèn)值為 -1,指示使用的是計(jì)算機(jī)的區(qū)域設(shè)置; LeadingDigit 三態(tài)常數(shù),指示是否顯示小數(shù)值小數(shù)點(diǎn)前面的零。
EXAMPLE: <%=FormatCurrency(34.3456)%>
RESULT: $34.35
FormatDateTime()
FUNCTION: 返回表達(dá)式,此表達(dá)式已被格式化為日期或時(shí)間
SYNTAX: FormatDateTime(Date, [, NamedFormat])
ARGUMENTS: NamedFormat 指示所使用的日期/時(shí)間格式的數(shù)值,如果省略,則使用 vbGeneralDate.
EXAMPLE: <%=FormatDateTime("08/4/99", vbLongDate)%>
RESULT: Wednesday, August 04, 1999
FormatNumber()
FUNCTION: 返回表達(dá)式,此表達(dá)式已被格式化為數(shù)值.
SYNTAX: FormatNumber(Expression [, Digit [, LeadingDigit [, Paren [, GroupDigit]]]])
ARGUMENTS: 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è)置。.
EXAMPLE: <%=FormatNumber(45.324567, 3)%>
RESULT: 45.325
FormatPercent()
FUNCTION: 返回表達(dá)式,此表達(dá)式已被格式化為尾隨有 % 符號(hào)的百分比(乘以 100 )。 (%)
SYNTAX: FormatPercent(Expression [, Digit [, LeadingDigit [, Paren [, GroupDigit]]]])
ARGUMENTS: 同上.
EXAMPLE: <%=FormatPercent(0.45267, 3)%>
RESULT: 45.267%
Hour()
FUNCTION: 以24時(shí)返回小時(shí)數(shù).
SYNTAX: Hour(time)
ARGUMENTS:
EXAMPLE: <%=Hour(#4:45:34 PM#)%>
RESULT: 16
(Hour has been converted to 24-hour system)
Instr()
FUNCTION: 返回字符或字符串在另一個(gè)字符串中第一次出現(xiàn)的位置.
SYNTAX: Instr([start, > strToBeSearched, strSearchFor [, compare>)
ARGUMENTS: Start為搜索的起始值,strToBeSearched接受搜索的字符串 strSearchFor要搜索的字符compare 比較方式(詳細(xì)見(jiàn)ASP常數(shù))
EXAMPLE: <%
strText = "This is a test!!"
pos = Instr(strText, "a")
response.write pos
%>
RESULT: 9
InstrRev()
FUNCTION: 同上,只是從字符串的最后一個(gè)搜索起
SYNTAX: InstrRev([start, > strToBeSearched, strSearchFor [, compare])
ARGUMENTS: 同上.
EXAMPLE: <%
strText = "This is a test!!"
pos = InstrRev(strText, "s")
response.write pos
%>
RESULT: 13
Int()
FUNCTION: 返回?cái)?shù)值類(lèi)型,不四舍五入。
SYNTAX: Int(number)
ARGUMENTS:
EXAMPLE: <%=INT(32.89)%>
RESULT: 32
IsArray()
FUNCTION: 判斷一對(duì)象是否為數(shù)組,返回布爾值 .
SYNTAX: IsArray(name)
ARGUMENTS:
EXAMPLE: <%
strTest = "Test!"
response.write IsArray(strTest)
%>
RESULT: False
IsDate()
FUNCTION: 判斷一對(duì)象是否為日期,返回布爾值
SYNTAX: IsDate(expression)
ARGUMENTS: expression is any valid expression.
EXAMPLE: <%
strTest = "8/4/99"
response.write IsDate(strTest)
%>
RESULT: True
IsEmpty()
FUNCTION: 判斷一對(duì)象是否初始化,返回布爾值.
SYNTAX: IsEmpty(expression)
ARGUMENTS:
EXAMPLE: <%
Dim i
response.write IsEmpty(i)
%>
RESULT: True
IsNull()
FUNCTION: 判斷一對(duì)象是否為空,返回布爾值.
SYNTAX: IsNull(expression)
ARGUMENTS:
EXAMPLE: <%
Dim i
response.write IsNull(i)
%>
RESULT: False
IsNumeric()
FUNCTION: 判斷一對(duì)象是否為數(shù)字,返回布爾值.
SYNTAX: IsNumeric(expression)
ARGUMENTS:
EXAMPLE: <%
i = "345"
response.write IsNumeric(i)
%>
RESULT: True
就算數(shù)字加了引號(hào),ASP還是認(rèn)為它是數(shù)字。
IsObject()
FUNCTION: 判斷一對(duì)象是否為對(duì)象,返回布爾值.
SYNTAX: IsObject(expression)
ARGUMENTS:
EXAMPLE: <%
Set con = Server.CreateObject("ADODB.Connection")
response.write IsObject(con)
%>
RESULT: True
LBound()
FUNCTION: 返回指定數(shù)組維的最小可用下標(biāo).
SYNTAX: Lbound(arrayname [, dimension])
ARGUMENTS: dimension 指明要返回哪一維下界的整數(shù)。使用 1 表示第一維,2 表示第二維,以此類(lèi) 推。如果省略 dimension 參數(shù),默認(rèn)值為 1.
EXAMPLE: <%
i = Array("Monday","Tuesday","Wednesday")
response.write LBound(i)
%>
RESULT: 0
LCase()
FUNCTION: 返回字符串的小寫(xiě)形式
SYNTAX: Lcase(string)
ARGUMENTS: string is any valid string expression.
EXAMPLE: <%
strTest = "This is a test!"
response.write LCase(strTest)
%>
RESULT: this is a test!
Left()
FUNCTION: 返回字符串左邊第length個(gè)字符以前的字符(含第length個(gè)字符).
SYNTAX: Left(string, length)
ARGUMENTS:
EXAMPLE: <%
strTest = "This is a test!"
response.write Left(strTest, 3)
%>
RESULT: Thi
Len()
FUNCTION: 返回字符串的長(zhǎng)度.
SYNTAX: Len(string | varName)
ARGUMENTS:
EXAMPLE: <%
strTest = "This is a test!"
response.write Len(strTest)
%>
RESULT: 15
LTrim()
FUNCTION: 去掉字符串左邊的空格.
SYNTAX: LTrim(string)
ARGUMENTS:
EXAMPLE: <%
strTest = " This is a test!"
response.write LTrim(strTest)
%>
RESULT: This is a test!
Mid()
FUNCTION: 返回特定長(zhǎng)度的字符串(從start開(kāi)始,長(zhǎng)度為length).
SYNTAX: Mid(string, start [, length])
ARGUMENTS:
EXAMPLE: <%
strTest = "This is a test! Today is Monday."
response.write Mid(strTest, 17, 5)
%>
RESULT: Today
Minute()
FUNCTION: 返回時(shí)間的分鐘
SYNTAX: Minute(time)
ARGUMENTS:
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.
EXAMPLE: <%
strTest = "This is an apple!"
response.write Replace(strTest, "apple", "orange")
%>
RESULT: This is an orange!
Right()
FUNCTION: 返回字符串右邊第length個(gè)字符以前的字符(含第length個(gè)字符).
SYNTAX: Right(string, length)
ARGUMENTS: .
EXAMPLE: <%
strTest = "This is an test!"
response.write Right(strTest, 3)
%>
RESULT: st!
Rnd()
FUNCTION: 產(chǎn)生一個(gè)隨機(jī)數(shù).
SYNTAX: Rnd [ (number) ]
ARGUMENTS:
EXAMPLE: <%
Randomize()
response.write RND()
%>
RESULT: 任何一個(gè)在0 到 1 之間的數(shù)
Round()
FUNCTION: 返回按指定位數(shù)進(jìn)行四舍五入的數(shù)值.
SYNTAX: Round(expression [, numRight])
ARGUMENTS: numRight數(shù)字表明小數(shù)點(diǎn)右邊有多少位進(jìn)行四舍五入。如果省略,則 Round 函數(shù)返回整數(shù).
EXAMPLE: <%
i = 32.45678
response.write Round(i)
%>
RESULT: 32
ASP函數(shù)詳解(1)
http://www.yzcc.com/2005/1-16/09311124554.html
Array()
FUNCTION: 返回一個(gè)數(shù)組
SYNTAX: Array(list)
ARGUMENTS: 字符,數(shù)字均可
EXAMPLE: <%
Dim myArray()
For i = 1 to 7
Redim Preserve myArray(i)
myArray(i) = WeekdayName(i)
Next
%>
RESULT: 建立了一個(gè)包含7個(gè)元素的數(shù)組myArray
myArray("Sunday","Monday", ... ... "Saturday")
CInt()
FUNCTION: 將一個(gè)表達(dá)式轉(zhuǎn)化為數(shù)字類(lèi)型
SYNTAX: CInt(expression)
ARGUMENTS: 任何有效的字符均可
EXAMPLE: <%
f = "234"
response.write cINT(f) + 2
%>
RESULT: 236
轉(zhuǎn)化字符"234"為數(shù)字"234",如果字符串為空,則返回0值
CreateObject()
FUNCTION: 建立和返回一個(gè)已注冊(cè)的ACTIVEX組件的實(shí)例。
SYNTAX: CreateObject(objName)
ARGUMENTS: objName 是任何一個(gè)有效、已注冊(cè)的ACTIVEX組件的名字.
EXAMPLE: <%
Set con = Server.CreateObject("ADODB.Connection")
%>
RESULT:
CStr()
FUNCTION: 轉(zhuǎn)化一個(gè)表達(dá)式為字符串.
SYNTAX: CStr(expression)
ARGUMENTS: expression 是任何有效的表達(dá)式。
EXAMPLE: <%
s = 3 + 2
response.write "The result is: " & cStr(s)
%>
RESULT: 轉(zhuǎn)化數(shù)字“5”為字符“5”。
Date()
FUNCTION: 返回當(dāng)前系統(tǒng)日期.
SYNTAX: Date()
ARGUMENTS: None.
EXAMPLE: <%=Date%>
RESULT: 8/4/99
DateAdd()
FUNCTION: 返回一個(gè)被改變了的日期。
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.
EXAMPLE: <%
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
%>
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: 返回兩個(gè)日期之間的差值 。
SYNTAX: DateDiff(timeinterval,date1,date2 [, firstdayofweek [, firstweekofyear]])
ARGUMENTS: timeinterval 表示相隔時(shí)間的類(lèi)型,如“M“表示“月”。
EXAMPLE: <%
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: 返回一個(gè)月的第幾日 .
SYNTAX: Day(date)
ARGUMENTS: date 是任何有效的日期。
EXAMPLE: <%=Day(#8/4/99#)%>
RESULT: 4
FormatCurrency()
FUNCTION: 返回表達(dá)式,此表達(dá)式已被格式化為貨幣值
SYNTAX: FormatCurrency(Expression [, Digit [, LeadingDigit [, Paren [, GroupDigit]]]])
ARGUMENTS: Digit 指示小數(shù)點(diǎn)右側(cè)顯示位數(shù)的數(shù)值。默認(rèn)值為 -1,指示使用的是計(jì)算機(jī)的區(qū)域設(shè)置; LeadingDigit 三態(tài)常數(shù),指示是否顯示小數(shù)值小數(shù)點(diǎn)前面的零。
EXAMPLE: <%=FormatCurrency(34.3456)%>
RESULT: $34.35
FormatDateTime()
FUNCTION: 返回表達(dá)式,此表達(dá)式已被格式化為日期或時(shí)間
SYNTAX: FormatDateTime(Date, [, NamedFormat])
ARGUMENTS: NamedFormat 指示所使用的日期/時(shí)間格式的數(shù)值,如果省略,則使用 vbGeneralDate.
EXAMPLE: <%=FormatDateTime("08/4/99", vbLongDate)%>
RESULT: Wednesday, August 04, 1999
FormatNumber()
FUNCTION: 返回表達(dá)式,此表達(dá)式已被格式化為數(shù)值.
SYNTAX: FormatNumber(Expression [, Digit [, LeadingDigit [, Paren [, GroupDigit]]]])
ARGUMENTS: 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è)置。.
EXAMPLE: <%=FormatNumber(45.324567, 3)%>
RESULT: 45.325
FormatPercent()
FUNCTION: 返回表達(dá)式,此表達(dá)式已被格式化為尾隨有 % 符號(hào)的百分比(乘以 100 )。 (%)
SYNTAX: FormatPercent(Expression [, Digit [, LeadingDigit [, Paren [, GroupDigit]]]])
ARGUMENTS: 同上.
EXAMPLE: <%=FormatPercent(0.45267, 3)%>
RESULT: 45.267%
Hour()
FUNCTION: 以24時(shí)返回小時(shí)數(shù).
SYNTAX: Hour(time)
ARGUMENTS:
EXAMPLE: <%=Hour(#4:45:34 PM#)%>
RESULT: 16
(Hour has been converted to 24-hour system)
Instr()
FUNCTION: 返回字符或字符串在另一個(gè)字符串中第一次出現(xiàn)的位置.
SYNTAX: Instr([start, > strToBeSearched, strSearchFor [, compare>)
ARGUMENTS: Start為搜索的起始值,strToBeSearched接受搜索的字符串 strSearchFor要搜索的字符compare 比較方式(詳細(xì)見(jiàn)ASP常數(shù))
EXAMPLE: <%
strText = "This is a test!!"
pos = Instr(strText, "a")
response.write pos
%>
RESULT: 9
InstrRev()
FUNCTION: 同上,只是從字符串的最后一個(gè)搜索起
SYNTAX: InstrRev([start, > strToBeSearched, strSearchFor [, compare])
ARGUMENTS: 同上.
EXAMPLE: <%
strText = "This is a test!!"
pos = InstrRev(strText, "s")
response.write pos
%>
RESULT: 13
Int()
FUNCTION: 返回?cái)?shù)值類(lèi)型,不四舍五入。
SYNTAX: Int(number)
ARGUMENTS:
EXAMPLE: <%=INT(32.89)%>
RESULT: 32
IsArray()
FUNCTION: 判斷一對(duì)象是否為數(shù)組,返回布爾值 .
SYNTAX: IsArray(name)
ARGUMENTS:
EXAMPLE: <%
strTest = "Test!"
response.write IsArray(strTest)
%>
RESULT: False
IsDate()
FUNCTION: 判斷一對(duì)象是否為日期,返回布爾值
SYNTAX: IsDate(expression)
ARGUMENTS: expression is any valid expression.
EXAMPLE: <%
strTest = "8/4/99"
response.write IsDate(strTest)
%>
RESULT: True
IsEmpty()
FUNCTION: 判斷一對(duì)象是否初始化,返回布爾值.
SYNTAX: IsEmpty(expression)
ARGUMENTS:
EXAMPLE: <%
Dim i
response.write IsEmpty(i)
%>
RESULT: True
IsNull()
FUNCTION: 判斷一對(duì)象是否為空,返回布爾值.
SYNTAX: IsNull(expression)
ARGUMENTS:
EXAMPLE: <%
Dim i
response.write IsNull(i)
%>
RESULT: False
IsNumeric()
FUNCTION: 判斷一對(duì)象是否為數(shù)字,返回布爾值.
SYNTAX: IsNumeric(expression)
ARGUMENTS:
EXAMPLE: <%
i = "345"
response.write IsNumeric(i)
%>
RESULT: True
就算數(shù)字加了引號(hào),ASP還是認(rèn)為它是數(shù)字。
IsObject()
FUNCTION: 判斷一對(duì)象是否為對(duì)象,返回布爾值.
SYNTAX: IsObject(expression)
ARGUMENTS:
EXAMPLE: <%
Set con = Server.CreateObject("ADODB.Connection")
response.write IsObject(con)
%>
RESULT: True
LBound()
FUNCTION: 返回指定數(shù)組維的最小可用下標(biāo).
SYNTAX: Lbound(arrayname [, dimension])
ARGUMENTS: dimension 指明要返回哪一維下界的整數(shù)。使用 1 表示第一維,2 表示第二維,以此類(lèi) 推。如果省略 dimension 參數(shù),默認(rèn)值為 1.
EXAMPLE: <%
i = Array("Monday","Tuesday","Wednesday")
response.write LBound(i)
%>
RESULT: 0
LCase()
FUNCTION: 返回字符串的小寫(xiě)形式
SYNTAX: Lcase(string)
ARGUMENTS: string is any valid string expression.
EXAMPLE: <%
strTest = "This is a test!"
response.write LCase(strTest)
%>
RESULT: this is a test!
Left()
FUNCTION: 返回字符串左邊第length個(gè)字符以前的字符(含第length個(gè)字符).
SYNTAX: Left(string, length)
ARGUMENTS:
EXAMPLE: <%
strTest = "This is a test!"
response.write Left(strTest, 3)
%>
RESULT: Thi
Len()
FUNCTION: 返回字符串的長(zhǎng)度.
SYNTAX: Len(string | varName)
ARGUMENTS:
EXAMPLE: <%
strTest = "This is a test!"
response.write Len(strTest)
%>
RESULT: 15
LTrim()
FUNCTION: 去掉字符串左邊的空格.
SYNTAX: LTrim(string)
ARGUMENTS:
EXAMPLE: <%
strTest = " This is a test!"
response.write LTrim(strTest)
%>
RESULT: This is a test!
Mid()
FUNCTION: 返回特定長(zhǎng)度的字符串(從start開(kāi)始,長(zhǎng)度為length).
SYNTAX: Mid(string, start [, length])
ARGUMENTS:
EXAMPLE: <%
strTest = "This is a test! Today is Monday."
response.write Mid(strTest, 17, 5)
%>
RESULT: Today
Minute()
FUNCTION: 返回時(shí)間的分鐘
SYNTAX: Minute(time)
ARGUMENTS:
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; strRepl, aceWith 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.
EXAMPLE: <%
strTest = "This is an apple!"
response.write Replace(strTest, "apple", "orange")
%>
RESULT: This is an orange!
Right()
FUNCTION: 返回字符串右邊第length個(gè)字符以前的字符(含第length個(gè)字符).
SYNTAX: Right(string, length)
ARGUMENTS: .
EXAMPLE: <%
strTest = "This is an test!"
response.write Right(strTest, 3)
%>
RESULT: st!
Rnd()
FUNCTION: 產(chǎn)生一個(gè)隨機(jī)數(shù).
SYNTAX: Rnd [ (number) ]
ARGUMENTS:
EXAMPLE: <%
Randomize()
response.write RND()
%>
RESULT: 任何一個(gè)在0 到 1 之間的數(shù)
Round()
FUNCTION: 返回按指定位數(shù)進(jìn)行四舍五入的數(shù)值.
SYNTAX: Round(expression [, numRight])
ARGUMENTS: numRight數(shù)字表明小數(shù)點(diǎn)右邊有多少位進(jìn)行四舍五入。如果省略,則 Round 函數(shù)返回整數(shù).
EXAMPLE: <%
i = 32.45678
response.write Round(i)
%>
RESULT: 32
http://www.bc-cn.net/Article/web/asp/jszl/200410/194.html
ASP語(yǔ)法速查表
作者:佚名 文章來(lái)源:不詳 點(diǎn)擊數(shù):1474 更新時(shí)間:2004-10-16
VBScript 函數(shù)
功能說(shuō)明
例子
Abs (數(shù)值) 絕對(duì)值。一個(gè)數(shù)字的絕對(duì)值是它的正值?兆址 (null) 的絕對(duì)值,也是空字符串。未初始化的變數(shù),其絕對(duì)為 0 例子:ABS(-2000)
結(jié)果:2000
Array (以逗點(diǎn)分隔的數(shù)組元素) Array 函數(shù)傳回?cái)?shù)組元素的值。 例子:
A=Array(1,2,3)
B=A(2)
結(jié)果: 2
說(shuō)明:變量B為A數(shù)組的第二個(gè)元素的值。
Asc (字符串) 將字符串的第一字母轉(zhuǎn)換成 ANSI (美國(guó)國(guó)家標(biāo)準(zhǔn)符號(hào))字碼。 例子:Asc(”Internet”)
結(jié)果:73
說(shuō)明:顯示第一字母 I 的 ANSI 字碼。
CBool(表達(dá)式) 轉(zhuǎn)換成布爾邏輯值變量型態(tài)(True 或False ) 例子:CBool(1+2)
結(jié)果:True
CDate (日期表達(dá)式) 換成日期變量型態(tài)?上仁褂 IsDate 函數(shù)判斷是否可以轉(zhuǎn)換成日 期。 例子: CDate (now( )+2)
結(jié)果:2000/5/28 10:30:59
CDbl(表達(dá)式) 轉(zhuǎn)換成DOUBLE變量型態(tài)。
Chr ( ANSI 字碼) 將ASCII 字碼轉(zhuǎn)換成字符。 例子: Chr ( 72 )
結(jié)果: H
CInt (表達(dá)式) 轉(zhuǎn)換成整數(shù)變量型態(tài)。 例子: CInt ("3.12")
結(jié)果: 3
CLng (表達(dá)式) 轉(zhuǎn)換成LONG 變量型態(tài)。
CSng (表達(dá)式) 轉(zhuǎn)換成SINGLE 變量型態(tài)。
CStr (表達(dá)式) 轉(zhuǎn)換成字符串變量型態(tài)。
Date ( )top 傳回系統(tǒng)的日期。 例子: Date
結(jié)果: 2000/5/13
DateAdd ( I , N , D ) 將一個(gè)日期加上一段期間后的日期。 I :設(shè)定一個(gè)日期( Date )所加上的一段期間的單位。譬如 interval="d" 表示 N的單位為日。 I的設(shè)定值如下:
yyyy Year 年
q Quarter 季
m Month 月
d Day 日
w Weekday 星期
h Hour 時(shí)
n Minute 分
s Second 秒
N :數(shù)值表達(dá)式,設(shè)定一個(gè)日期所加上的一段期間,可為正值或負(fù)值,正值表示加(結(jié)果為 >date 以后的日期),負(fù)值表示減(結(jié)果為 >date 以前的日期)。
D :待加減的日期。 例子: DateAdd ( "m" , 1 , "31-Jan-98")
結(jié)果: 28-Feb-98
說(shuō)明:將日期 31-Jan-98 加上一個(gè)月,結(jié)果為 28-Feb-98 而非 31-Fe-98 。
例子: DateAdd ( "d" , 20 , "30-Jan-99")
結(jié)果: 1999/2/9
說(shuō)明:將一個(gè)日期 30-Jan-99 加上 20 天后的日期。
DateDiff (I , D1 , D2[,FW[,FY]]) 計(jì)算兩個(gè)日期之間的期間。
I :設(shè)定兩個(gè)日期之間的期間計(jì)算之單位。譬如 >I="m" 表示計(jì)算的單位為月。 >I 的設(shè)定值如:
yyyy > Year 年
q Quarter 季
m Month 月
d Day 日
w Weekday 星期
h Hour 時(shí)
m Minute 分
s Second 秒
D1 ,D2:計(jì)算期間的兩個(gè)日期表達(dá)式,若 >date1 較早,則兩個(gè)日期之間的期間結(jié)果為正值;若 >date2 較早, 則結(jié)果為負(fù)值。
FW :設(shè)定每周第一天為星期幾, 若未設(shè)定表示為星期天。 >FW 的設(shè)定值如下:
0 使用 >API 的設(shè)定值。
1 星期天
2 星期一
3 星期二
4 星期三
5 星期四
6 星期五
7 星期六
FY :設(shè)定一年的第一周, 若未設(shè)定則表示一月一日那一周為一年的第一周。 >FY 的設(shè)定值如下:
0 使用 >API 的設(shè)定值。
1 一月一日那一周為一年的第一周
2 至少包括四天的第一周為一年的第一周
3 包括七天的第一周為一年的第一周 例子: DateDiff ("d","25-Mar-99 ","30-Jun-99 ")
結(jié)果: 97
說(shuō)明:顯示兩個(gè)日期之間的期間為 97 天。
DatePart (I,D,[,FW[,FY]]) 傳回一個(gè)日期的之部份。
>I :設(shè)定傳回那一部份。譬如 >I="d" 表示傳回 部份為日。 >I 的設(shè)定值如下:
yyyy Year 年
q Quarter 季
m Month 月
d Day 日
w Weekday 星期
h Hour 時(shí)
m Minute 分
s Second 秒
D :待計(jì)算的日期。
>FW :設(shè)定每周第一天為星期幾, 若未設(shè)定則表示為星期天。 >FW 的設(shè)定值如下:
0 使用 >API 的設(shè)定值。
1 星期天
2 星期一>3 星期二
4 星期三
5 星期四
6 星期五
7 星期六
FY :設(shè)定一年的第一周, 若未設(shè)定則表示一月一日那一周為一年的第一周。 >FY 的設(shè)定值如下:
0 使用 >API 的設(shè)定值。
1 一月一日那一周為一年的第一周
2 至少包括四天的第一周為一年的第一周
3 包括七天的第一周為一年的第一周 例子: DatePart ("m","25-Mar-99 ")
結(jié)果: 3
說(shuō)明:顯示傳回一個(gè)日期 的月部份。
Dateserial (year,month,day) 轉(zhuǎn)換(year,month,day) 成日期變量型態(tài)。 例子: DateSerial (99,10,1)
結(jié)果: 1999/10/1
Datevalue ( 日期的字符串或表達(dá)式 ) 轉(zhuǎn)換成日期變量型態(tài),日期從 January 1,100 到 December 31,9999 。格式為 month,day,and year 或 month/day/year 。譬如: December 30,1999 、 Dec 30,1999 、 12/30/1999 、 12/30/99 例子: Datevalue ("January 1,2002 ")
結(jié)果: 2002/1/1
Day( 日期的字符串或表達(dá)式 ) 傳回日期的「日」部份。 例子: Day(" 12/1/1999 ")
結(jié)果: 1
Fix( 表達(dá)式 )top 轉(zhuǎn)換字符串成整數(shù)數(shù)字型態(tài)。與 Int 函數(shù)相同。若為 null 時(shí)傳回 null 。
Int (number) 與 Fix(number) 的差別在負(fù)數(shù)。如 Int (-5.6)=-6 , Fix(-5.6)=-5 。 例子: Fix(5.6)
結(jié)果: 5
Hex( 表達(dá)式 )top 傳回?cái)?shù)值的十六進(jìn)制值。若表達(dá)式為 null 時(shí) Hex( 表達(dá)式 )=null ,若表達(dá)式 =Empty 時(shí) Hex( 表達(dá)式 )=0 。 16 進(jìn)位可以加「 &H 」表示,譬如 16 進(jìn)位 &H10 表示十進(jìn)制的 16 。 例子: Hex(30)
結(jié)果: 1E
Hour( 時(shí)間的字符串或表達(dá)式 ) 傳回時(shí)間的「小時(shí)」部份。 例子: Hour("12:30:54 ")
結(jié)果: 12
InStr ([start,]string1,string2[,compare]) top 將一 個(gè) 字符串由左 而右與另一個(gè)比較,傳回第一個(gè)相同的位置。
start 為從第幾個(gè)字比較起,若省略 start 則從第一個(gè)字比較起, string1 為待尋找的字符串表達(dá)式, string2 為 待比較的字符串表達(dá)式, compare 為比較的方法, compare=0 表二進(jìn)制比較法, compare=1 表文字比較法,若省略 compare 則為預(yù)設(shè)的二進(jìn)制比較法。 例子: InStr("abc123def123","12")
結(jié)果: 4
InstrRev ([start,]string1,string2[,compare]) 將一 個(gè) 字符串 由右而左與另一個(gè)比較,傳回第一個(gè)相同的位置。
start 為從第幾個(gè)字比較起,若省略 start 則從第一個(gè)字比較起, string1 為待尋找的字符串表達(dá)式, string2 為 待比較的字符串表達(dá)式, compare 為比較的方法, compare=0 表二進(jìn)制比較法, compare=1 表文字比較法,若省略 compare 則為預(yù)設(shè)的二進(jìn)制比較法。 例子: InstrRev ("abc123def123","12")
結(jié)果: 10
Int ( 表達(dá)式 ) 傳回一個(gè)數(shù)值的整數(shù)部份。與 Fix 函數(shù)相同。 例子: Int (5.6)
結(jié)果: 5
IsArray ( 變數(shù) ) 測(cè)試變量是 (True) 否 (False) 是一個(gè)數(shù)組。 例子: IsArray (3)
結(jié)果: False
說(shuō)明:不是一個(gè)數(shù)組。
IsDate ( 日期或字符串的表達(dá)式 ) 是否可以轉(zhuǎn)換成日期。日期從 January 1,100 A.D. 到 December 31,9999 A.D 。 例子: IsDate ("December 31,1999 ")
結(jié)果: True
說(shuō)明:可以轉(zhuǎn)換成日期。
IsEmpty ( 變數(shù) ) 測(cè)試變量是 (True) 否 (False) 已經(jīng)被初始化 例子: IsEmpty (a)
結(jié)果: True
IsNull ( 變數(shù) ) 測(cè)試變數(shù)是 (True) 否 (False) 不是有效的數(shù)據(jù)。 例子: IsNull ("")
結(jié)果: False
說(shuō)明:是有效的數(shù)據(jù)。
IsNumeric ( 表達(dá)式 ) 是 (True) 否 (False) 是數(shù)字。 例子: IsNumeric ("abc123")
結(jié)果: False
說(shuō)明:不是數(shù)字。
LCase ( 字符串表達(dá)式 ) top 轉(zhuǎn)換字符串成小寫(xiě)。將大寫(xiě)字母的部份轉(zhuǎn)換成小寫(xiě)。字符串其余的部份不變。 例子: LCase ("ABC123")
結(jié)果: abc123
Left( 字符串表達(dá)式 ,length) 取字符串左邊的幾個(gè)字。 length 為取個(gè)字。 Len 函數(shù)可得知字符串的長(zhǎng)度。 例子: Left("ABC123",3)
結(jié)果: ABC
Len( 字符串表達(dá)式 變量 ) 取得字符串的長(zhǎng)度。 例子: Len("ABC123")
結(jié)果: 6
LTrim ( 字符串表達(dá)式 ) 除去字符串左邊的空白字。 RTrim 除去字符串右邊的空白字, Trim 函數(shù)除去字符串左右兩邊的空白字。 例子: LTrim ("456+" abc ")
結(jié)果: 456abc123
Mid( 字符串表達(dá)式 ,start[,length]) top 取字符串中的幾個(gè)字。 start 為從第幾個(gè) 字取起, length 為取幾個(gè)字, 若略 length 則從 start 取到最右底。由Len 函數(shù)可得知字符串的長(zhǎng)度。 例子: Mid("abc123",2,3)
結(jié)果: c12
Minute( 日期的字符串或表達(dá)式 ) 傳回時(shí)間的「分鐘」部份。 例子: Minute("12:30:54")
結(jié)果:30
Month(日期的字符串或表達(dá)式) 傳回日期的「月」部份。 例子:Month("12/1/2001")
結(jié)果:12
MonthName(month[,abbreviate]) 傳回月的名稱。
month :待傳回月名稱的數(shù)字 1~12 。譬如, 1 代表一月, 7 代表七月。
abbreviate: 是 (True) 否 (False) 為縮寫(xiě),譬如 March ,縮寫(xiě)為 Mar 。默認(rèn)值為 False 。中文的月名稱無(wú)縮寫(xiě)。 例子: MonthName (7)
結(jié)果:七月
Now() 傳回系統(tǒng)的日期時(shí)間。 例子: Now()
結(jié)果: 2001/12/30 10:35:59 AM
Oct() 傳回?cái)?shù)值的八進(jìn)位值。八進(jìn)位可以加「 &O 」表示,譬如八進(jìn)位 &O10 表示十進(jìn)制的 8 。 例子: Oct(10)
結(jié)果: 12
Replace( 字符串表達(dá)式,findnreplacewith[,start[,count[,compare]]]) 將一個(gè)字符串取代 部份字。尋找待取代的原字符串 (find) , 若找到則被取代為新字符串 (replacewith) 。
find :待尋找取代的原字符串。
replacewith :取代后的字。
start :從第幾個(gè)字開(kāi)始尋找取代, 若未設(shè)定則由第一個(gè)字開(kāi)始尋找。
count :取代的次數(shù)。 若未設(shè)定則所有尋找到的字符串取代字符 串全部被取代。
compare :尋找比較的方法, compare=0 表示二進(jìn)制比較法, compare=1 表文字比較法, compare =2 表根據(jù)比較的 數(shù)據(jù)型態(tài)而定,若省略 compare 則為預(yù)設(shè)的二進(jìn)制比較法。 例子: Replace("ABCD123ABC","AB","ab")
結(jié)果: abCD123abC
Right( 字符串表達(dá)式 ,length) 取字符串右邊的幾個(gè)字, length 為取幾個(gè)字。 Len 函數(shù)可得知字符串的長(zhǎng)度。 例子: Right("ABC123",3)
結(jié)果: 123
Rnd [(number)] 0~1 的 隨機(jī)隨機(jī)數(shù)值。 number 是任何有效的數(shù)值表達(dá)式。若 number 小于 0 表示每次得到相同的 隨機(jī)隨機(jī)數(shù)值。 number 大于 0 或未提供時(shí)表示依序得到下一個(gè) 隨機(jī)隨機(jī)數(shù)值。 >number=0 表示得到最近產(chǎn)生的 隨機(jī)隨機(jī)數(shù)值。為了避免得到相同的隨機(jī)隨機(jī)數(shù)順序,可以于 Rnd 函數(shù)前加 Randomize 。 例子: Rnd
結(jié)果: 0.498498
Round( 數(shù)值表達(dá)式 [,D]) 四舍五入。
D :為四舍五入到第幾位小數(shù),若省略則四舍五入到整數(shù)。 例子: Round(30635,1)
結(jié)果: 3.6
RTrim ( 字符串表達(dá)式 ) 除去字符串右邊的空白字。 LTrim 除去字符串左邊的空白字, Trim 函數(shù)除去字符串左右兩邊的空白字。 例子: RTrim ("abc123 ")+"456"
結(jié)果: abc123456
Second( 時(shí)間的字符串或表達(dá)式 )top 傳回時(shí)間的「秒」部份。 例子:Second("12:30:54")
結(jié)果:54
Space( 重復(fù)次數(shù) ) 得到重復(fù)相同的空白字符串。 例子: A"+Space (5)+"B
結(jié)果: A B
說(shuō)明: A 和 B 中間加入五個(gè)空白字。
String( 重復(fù)次數(shù),待重復(fù)的字 ) 得到重復(fù)相同的字符串。 例子: String(5,71)
結(jié)果: GGGGG
StrReverse (String(10,71)) 將一個(gè)字符串順序顛倒。 例子: StrReverse ("ABC")
結(jié)果: CBA
Time() 傳回系統(tǒng)的時(shí)間。 例子: Time
結(jié)果: 10:35:59 PM
TimeSerial (hour,minute,second) 轉(zhuǎn)換指定的 ( hour,minute,second) 成時(shí)間 變量型態(tài)。 例子: TimeSerial (10,31,59)
結(jié)果: 10:31:59
Timevalue ( 日期的字符串或表達(dá)式 ) 轉(zhuǎn)換 成時(shí)間變量型態(tài)。日期的字符串或表達(dá)式從 0:00:00(12:00:00 A.M.) 到 23:59:59(11:59:59 P.M.) 。 例子: Timevalue (" 11:59:59 ")
結(jié)果: 11:59:59
Trim( 字符串表達(dá)式 ) 除去字符串左右兩邊的空白字。 例子: Trim(" abc123 ")
結(jié)果: abc123
UCase ()top 轉(zhuǎn)換字符串成大寫(xiě)。將小寫(xiě)字母的部份轉(zhuǎn)換成大寫(xiě),字符串其余部份不變。 例子: UCase ("abc123")
結(jié)果: ABC123
VarType ( 變數(shù) ) 傳回一個(gè)變量類(lèi)型。與 TypeName 函數(shù)相同, VarType 傳回變量類(lèi)型的代碼, TypeName 傳回變量類(lèi)型的名稱。 例子: VarType ( "I love you!")
結(jié)果: 8
Weekday( 日期表達(dá)式 ,[FW]) 傳回星期幾的數(shù)字。
FW :設(shè)定一周的第一天是星期幾。若 省略則表 1( 星期日 ) 。
Firstdayfweek 設(shè)定值為: 1( 星期日 ),2( 星期一 ),3( 星期二 ),4( 星期三 ),5( 星期四 ),6( 星期五 ),7( 星期六 ) 。 例子: Weekday(" 1/1/2000")
結(jié)果: 7
WeekDayName (W,A,FW) 傳回星期幾的名稱。
W :是 (True) 否 (False) 為縮寫(xiě)。譬如 March ,縮寫(xiě)為 Mar 。預(yù)設(shè)為 False 。中文的星期幾名稱無(wú)縮寫(xiě)。
FW :設(shè)定一周的第一天是星期幾。 若省略表 1( 星期日 ) 。設(shè)定待傳回星期幾的名稱,為一周中的第幾天。
A : 1( 星期日 ),2( 星期一 ),3( 星期二 ),4( 星期三&, nbsp;),5( 星期四 ),6( 星期五 ),7( 星期六 ) 。 例子: WeekDayName ("1/1/2000")
結(jié)果:星期六
Year() 傳回日期的「年」部份。 例子: Year(" 12/1/2000 ")
結(jié)果: 2000
ASP中一種效率極高的分類(lèi)算法(一)
(2002年04月29日22:55:00 閱讀: 1 )
在網(wǎng)站建設(shè)中,分類(lèi)算法的應(yīng)用非常的普遍。在設(shè)計(jì)一個(gè)電子商店時(shí),要涉及到商品分類(lèi);在設(shè)計(jì)發(fā)布系統(tǒng)時(shí),要涉及到欄目或者頻道分類(lèi);在設(shè)計(jì)軟件下載這樣的程序時(shí),要涉及到軟件的分類(lèi);如此等等?梢哉f(shuō),分類(lèi)是一個(gè)很普遍的問(wèn)題。
我常常面試一些程序員,而且我?guī)缀鹾翢o(wú)例外地要問(wèn)他們一些關(guān)于分類(lèi)算法的問(wèn)題。下面的舉幾個(gè)我常常詢問(wèn)的問(wèn)題。你認(rèn)為你可以很輕松地回答么^_^.
1、分類(lèi)算法常常表現(xiàn)為樹(shù)的表示和遍歷問(wèn)題。那么,請(qǐng)問(wèn):如果用數(shù)據(jù)庫(kù)中的一個(gè)Table來(lái)表達(dá)樹(shù)型分類(lèi),應(yīng)該有幾個(gè)字段?
2、如何快速地從這個(gè)Table恢復(fù)出一棵樹(shù);
3、如何判斷某個(gè)分類(lèi)是否是另一個(gè)分類(lèi)的子類(lèi);
4、如何查找某個(gè)分類(lèi)的所有產(chǎn)品;
5、如何生成分類(lèi)所在的路徑。
6、如何新增分類(lèi);
在不限制分類(lèi)的級(jí)數(shù)和每級(jí)分類(lèi)的個(gè)數(shù)時(shí),這些問(wèn)題并不是可以輕松回答的。本文試圖解決這些問(wèn)題。
分類(lèi)的數(shù)據(jù)結(jié)構(gòu)
我們知道:分類(lèi)的數(shù)據(jù)結(jié)構(gòu)實(shí)際上是一棵樹(shù)。在《數(shù)據(jù)結(jié)構(gòu)》課程中,大家可能學(xué)過(guò)Tree的算法。由于在網(wǎng)站建設(shè)中我們大量使用數(shù)據(jù)庫(kù),所以我們將從Tree在數(shù)據(jù)庫(kù)中的存儲(chǔ)談起。
為簡(jiǎn)化問(wèn)題,我們假設(shè)每個(gè)節(jié)點(diǎn)只需要保留Name這一個(gè)信息。我們需要為每個(gè)節(jié)點(diǎn)編號(hào)。編號(hào)的方法有很多種。在數(shù)據(jù)庫(kù)中常用的就是自動(dòng)編號(hào)。這在Access、SQL Server、Oracle中都是這樣。假設(shè)編號(hào)字段為ID。
為了表示某個(gè)節(jié)點(diǎn)ID1是另外一個(gè)節(jié)點(diǎn)ID2的父節(jié)點(diǎn),我們需要在數(shù)據(jù)庫(kù)中再保留一個(gè)字段,說(shuō)明這個(gè)分類(lèi)是屬于哪個(gè)節(jié)點(diǎn)的兒子。把這個(gè)字段取名為FatherID。如這里的ID2,其FatherID就是ID1。
這樣,我們就得到了分類(lèi)Catalog的數(shù)據(jù)表定義:
Create Table [Catalog](
[ID] [int] NOT NULL,
[Name] [nvarchar](50) NOT NULL,
[FatherID] [int] NOT NULL
);
約定:我們約定用-1作為最上面一層分類(lèi)的父親編碼。編號(hào)為-1的分類(lèi)。這是一個(gè)虛擬的分類(lèi)。它在數(shù)據(jù)庫(kù)中沒(méi)有記錄。
如何恢復(fù)出一棵樹(shù)
上面的Catalog定義的最大優(yōu)勢(shì),就在于用它可以輕松地恢復(fù)出一棵樹(shù)—分類(lèi)樹(shù)。為了更清楚地展示算法,我們先考慮一個(gè)簡(jiǎn)單的問(wèn)題:怎樣顯示某個(gè)分類(lèi)的下一級(jí)分類(lèi)。我們知道,要查詢某個(gè)分類(lèi)FID的下一級(jí)分類(lèi),SQL語(yǔ)句非常簡(jiǎn)單:
select Name from catalog where FatherID=FID
顯示這些類(lèi)別時(shí),我們簡(jiǎn)單地用< LI>來(lái)做到:
< %
REM oConn---數(shù)據(jù)庫(kù)連接,調(diào)用GetChildren時(shí)已經(jīng)打開(kāi)
REM FID-----當(dāng)前分類(lèi)的編號(hào)
Function GetChildren(oConn,FID)
strSQL = "select ID,Name from catalog where FatherID="&FID
set rsCatalog = oConn.Execute(strSQL)
%>
< UL>
< %
Do while not rsCatalog.Eof
%>
< LI>< %=rsCatalog("Name")%>
< %
Loop
%>
< /UL>
< %
rsCatalog.Close
End Function
%>
現(xiàn)在我們來(lái)看看如何顯示FID下的所有分類(lèi)。這需要用到遞歸算法。我們只需要在GetChildren函數(shù)中簡(jiǎn)單地對(duì)所有ID進(jìn)行調(diào)用:GetChildren(oConn,Catalog(“ID”))就可以了。
< %
REM oConn---數(shù)據(jù)庫(kù)連接,已經(jīng)打開(kāi)
REM FID-----當(dāng)前分類(lèi)的編號(hào)
Function GetChildren(oConn,FID)
strSQL = "select Name from catalog where FatherID="&FID
set rsCatalog = oConn.Execute(strSQL)
%>
< UL>
< %
Do while not rsCatalog.Eof
%>
< LI>
< %=GetChildren(oConn,Catalog("ID"))%>
< %
Loop
%>
< /UL>
< %
rsCatalog.Close
End Function
%>
修改后的GetChildren就可以完成顯示FID分類(lèi)的所有子分類(lèi)的任務(wù)。要顯示所有的分類(lèi),只需要如此調(diào)用就可以了:
< %
REM strConn--連接數(shù)據(jù)庫(kù)的字符串,請(qǐng)根據(jù)情況修改
set oConn = Server.CreateObject("ADODB.Connection")
oConn.Open strConn
=GetChildren(oConn,-1)
oConn.Close
%>
如何查找某個(gè)分類(lèi)的所有產(chǎn)品;
現(xiàn)在來(lái)解決我們?cè)谇懊嫣岢龅牡谒膫(gè)問(wèn)題。第三個(gè)問(wèn)題留作習(xí)題。我們假設(shè)產(chǎn)品的數(shù)據(jù)表如下定義:
Create Table Product(
[ID] [int] NOT NULL,
[Name] [nvchar] NOT NULL,
[FatherID] [int] NOT NULL
);
其中,ID是產(chǎn)品的編號(hào),Name是產(chǎn)品的名稱,而FatherID是產(chǎn)品所屬的分類(lèi)。
對(duì)第四個(gè)問(wèn)題,很容易想到的辦法是:先找到這個(gè)分類(lèi)FID的所有子類(lèi),然后查詢所有子類(lèi)下的所有產(chǎn)品。實(shí)現(xiàn)這個(gè)算法實(shí)際上很復(fù)雜。代碼大致如下:
< %
Function GetAllID(oConn,FID)
Dim strTemp
If FID=-1 then
strTemp = ""
else
strTemp =","
end if
strSQL = "select Name from catalog where FatherID="&FID
set rsCatalog = oConn.Execute(strSQL)
Do while not rsCatalog.Eof
strTemp=strTemp&rsCatalog("ID")&GetAllID(oConn,Catalog("ID")) REM 遞歸調(diào)用
Loop
rsCatalog.Close
分類(lèi)算法要解決的問(wèn)題
在網(wǎng)站建設(shè)中,分類(lèi)算法的應(yīng)用非常的普遍。在設(shè)計(jì)一個(gè)電子商店時(shí),要涉及到商品分類(lèi);在設(shè)計(jì)發(fā)布系統(tǒng)時(shí),要涉及到欄目或者頻道分類(lèi);在設(shè)計(jì)軟件下載這樣的程序時(shí),要涉及到軟件的分類(lèi);如此等等?梢哉f(shuō),分類(lèi)是一個(gè)很普遍的問(wèn)題。
我常常面試一些程序員,而且我?guī)缀鹾翢o(wú)例外地要問(wèn)他們一些關(guān)于分類(lèi)算法的問(wèn)題。下面的舉幾個(gè)我常常詢問(wèn)的問(wèn)題。你認(rèn)為你可以很輕松地回答么^_^.
1、分類(lèi)算法常常表現(xiàn)為樹(shù)的表示和遍歷問(wèn)題。那么,請(qǐng)問(wèn):如果用數(shù)據(jù)庫(kù)中的一個(gè)Table來(lái)表達(dá)樹(shù)型分類(lèi),應(yīng)該有幾個(gè)字段?
2、如何快速地從這個(gè)Table恢復(fù)出一棵樹(shù);
3、如何判斷某個(gè)分類(lèi)是否是另一個(gè)分類(lèi)的子類(lèi);
4、如何查找某個(gè)分類(lèi)的所有產(chǎn)品;
5、如何生成分類(lèi)所在的路徑。
6、如何新增分類(lèi);
在不限制分類(lèi)的級(jí)數(shù)和每級(jí)分類(lèi)的個(gè)數(shù)時(shí),這些問(wèn)題并不是可以輕松回答的。本文試圖解決這些問(wèn)題。
分類(lèi)的數(shù)據(jù)結(jié)構(gòu)
我們知道:分類(lèi)的數(shù)據(jù)結(jié)構(gòu)實(shí)際上是一棵樹(shù)。在《數(shù)據(jù)結(jié)構(gòu)》課程中,大家可能學(xué)過(guò)Tree的算法。由于在網(wǎng)站建設(shè)中我們大量使用數(shù)據(jù)庫(kù),所以我們將從Tree在數(shù)據(jù)庫(kù)中的存儲(chǔ)談起。
為簡(jiǎn)化問(wèn)題,我們假設(shè)每個(gè)節(jié)點(diǎn)只需要保留Name這一個(gè)信息。我們需要為每個(gè)節(jié)點(diǎn)編號(hào)。編號(hào)的方法有很多種。在數(shù)據(jù)庫(kù)中常用的就是自動(dòng)編號(hào)。這在Access、SQL Server、Oracle中都是這樣。假設(shè)編號(hào)字段為ID。
為了表示某個(gè)節(jié)點(diǎn)ID1是另外一個(gè)節(jié)點(diǎn)ID2的父節(jié)點(diǎn),我們需要在數(shù)據(jù)庫(kù)中再保留一個(gè)字段,說(shuō)明這個(gè)分類(lèi)是屬于哪個(gè)節(jié)點(diǎn)的兒子。把這個(gè)字段取名為FatherID。如這里的ID2,其FatherID就是ID1。
這樣,我們就得到了分類(lèi)Catalog的數(shù)據(jù)表定義:
Create Table [Catalog](
[ID] [int] NOT NULL,
[Name] [nvarchar](50) NOT NULL,
[FatherID] [int] NOT NULL
);
約定:我們約定用-1作為最上面一層分類(lèi)的父親編碼。編號(hào)為-1的分類(lèi)。這是一個(gè)虛擬的分類(lèi)。它在數(shù)據(jù)庫(kù)中沒(méi)有記錄。
如何恢復(fù)出一棵樹(shù)
上面的Catalog定義的最大優(yōu)勢(shì),就在于用它可以輕松地恢復(fù)出一棵樹(shù)—分類(lèi)樹(shù)。為了更清楚地展示算法,我們先考慮一個(gè)簡(jiǎn)單的問(wèn)題:怎樣顯示某個(gè)分類(lèi)的下一級(jí)分類(lèi)。我們知道,要查詢某個(gè)分類(lèi)FID的下一級(jí)分類(lèi),SQL語(yǔ)句非常簡(jiǎn)單:
select Name from catalog where FatherID=FID
顯示這些類(lèi)別時(shí),我們簡(jiǎn)單地用〈 LI〉來(lái)做到:
〈%
REM oConn---數(shù)據(jù)庫(kù)連接,調(diào)用GetChildren時(shí)已經(jīng)打開(kāi)
REM FID-----當(dāng)前分類(lèi)的編號(hào)
Function GetChildren(oConn,FID)
strSQL = "select ID,Name from catalog where FatherID="&FID
set rsCatalog = oConn.Execute(strSQL)
%〉
〈UL〉
〈%
Do while not rsCatalog.Eof
%〉
〈LI〉〈%=rsCatalog("Name")%〉
〈%
Loop
%〉
〈/UL〉
〈%
rsCatalog.Close
End Function
%〉
現(xiàn)在我們來(lái)看看如何顯示FID下的所有分類(lèi)。這需要用到遞歸算法。我們只需要在GetChildren函數(shù)中簡(jiǎn)單地對(duì)所有ID進(jìn)行調(diào)用:GetChildren(oConn,Catalog(“ID”))就可以了。
〈%
REM oConn---數(shù)據(jù)庫(kù)連接,已經(jīng)打開(kāi)
REM FID-----當(dāng)前分類(lèi)的編號(hào)
Function GetChildren(oConn,FID)
strSQL = "select Name from catalog where FatherID="&FID
set rsCatalog = oConn.Execute(strSQL)
%〉
〈UL〉
〈%
Do while not rsCatalog.Eof
%〉
〈LI〉〈%=rsCatalog("Name")%〉
〈%=GetChildren(oConn,Catalog("ID"))%〉
〈%
Loop
%〉
〈/UL〉
〈%
rsCatalog.Close
End Function
%〉
修改后的GetChildren就可以完成顯示FID分類(lèi)的所有子分類(lèi)的任務(wù)。要顯示所有的分類(lèi),只需要如此調(diào)用就可以了:
〈%
REM strConn--連接數(shù)據(jù)庫(kù)的字符串,請(qǐng)根據(jù)情況修改
set oConn = Server.CreateObject("ADODB.Connection")
oConn.Open strConn
=GetChildren(oConn,-1)
oConn.Close
%〉
如何查找某個(gè)分類(lèi)的所有產(chǎn)品;
現(xiàn)在來(lái)解決我們?cè)谇懊嫣岢龅牡谒膫(gè)問(wèn)題。第三個(gè)問(wèn)題留作習(xí)題。我們假設(shè)產(chǎn)品的數(shù)據(jù)表如下定義:
Create Table Product(
[ID] [int] NOT NULL,
[Name] [nvchar] NOT NULL,
[FatherID] [int] NOT NULL
);
其中,ID是產(chǎn)品的編號(hào),Name是產(chǎn)品的名稱,而FatherID是產(chǎn)品所屬的分類(lèi)。
對(duì)第四個(gè)問(wèn)題,很容易想到的辦法是:先找到這個(gè)分類(lèi)FID的所有子類(lèi),然后查詢所有子類(lèi)下的所有產(chǎn)品。實(shí)現(xiàn)這個(gè)算法實(shí)際上很復(fù)雜。代碼大致如下:
〈%
Function GetAllID(oConn,FID)
Dim strTemp
If FID=-1 then
strTemp = ""
else
strTemp =","
end if
strSQL = "select Name from catalog where FatherID="&FID
set rsCatalog = oConn.Execute(strSQL)
Do while not rsCatalog.Eof
strTemp=strTemp&rsCatalog("ID")&GetAllID(oConn,Catalog("ID")) REM 遞歸調(diào)用
Loop
rsCatalog.Close
GetAllID = strTemp
End Function
REM strConn--連接數(shù)據(jù)庫(kù)的字符串,請(qǐng)根據(jù)情況修改
set oConn = Server.CreateObject("ADODB.Connection")
oConn.Open strConn
FID = Request.QueryString("FID")
strSQL = "select top 100 * from Product where FatherID in ("&GetAllID(oConn,FID)&")"
set rsProduct=oConn.Execute(strSQL)
%〉
〈UL〉〈%
Do while not rsProduct.EOF
%〉
〈LI〉〈%=rsProduct("Name")%〉
〈%
Loop
%〉
〈/UL〉
〈%rsProduct.Close
oConn.Close
%〉
一個(gè)asp加密方法(好像是什么什么RSA,上次朋友相托寫(xiě)的)存為html就行了
<%
Class clsRSA
Public Key
Public Sub GetKey()
Key=3
end Sub
Public Function Encode(ByVal Message)
On Error Resume Next
Dim L_Message
Dim i
Dim Asc_Message
L_Message = Len(Message)
If L_Message = 0 Then Exit Function
call GetKey()
For i = 1 To L_Message
Asc_Message = Asc(Mid(Message,i, 1))
if Asc_Message\2=0 then
Asc_Message=Asc_Message+key
else
Asc_Message=Asc_Message+key+1
end if
Encode=Encode & Chr(Asc_Message)
next
End Function
Public Function Decode(ByVal Message)
On Error Resume Next
Dim L_Message
Dim i
Dim Asc_Message
L_Message = Len(Message)
If L_Message = 0 Then Exit Function
call GetKey()
For i = 1 To L_Message
Asc_Message = Asc(Mid(Message,i, 1))
if (Asc_Message - Key)\2=0 then
Asc_Message=Asc_Message - Key
else
Asc_Message=Asc_Message - Key-1
end if
Decode=Decode & Chr(Asc_Message)
next
End Function
End Class
key = "138505633zzszyzf"
Set ObjRSA = New clsRSA
pass=request("pass")
if pass<>"" then enpass= ObjRSA.Decode(pass)
%>
<head>
<title>1234</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<style>BODY,TD,INPUT{}{FONT-SIZE:9PT}</style>
</head>
<body bgcolor="#FFFFFF" text="#000000">
<form name="enpass" method="post" >
密文:<input type="text" name="pass" value="<%=Pass%>">
<input type="submit" name="Submit" value="解密">
</form>
明文:<input type=text size=34 maxlength=16 value=’<%=enpass%>’>
</body>
Class clsRSA
Public PrivateKey
Public PublicKey
Public Modulus
Public Function Crypt(pLngMessage, pLngKey)
On Error Resume Next
Dim lLngMod
Dim lLngResult
Dim lLngIndex
If pLngKey Mod 2 = 0 Then
lLngResult = 1
For lLngIndex = 1 To pLngKey / 2
lLngMod = (pLngMessage ^ 2) Mod Modulus
’’ Mod may error on key generation
lLngResult = (lLngMod * lLngResult) Mod Modulus
If Err Then Exit Function
Next
Else
lLngResult = pLngMessage
For lLngIndex = 1 To pLngKey / 2
lLngMod = (pLngMessage ^ 2) Mod Modulus
On Error Resume Next
’’ Mod may error on key generation
lLngResult = (lLngMod * lLngResult) Mod Modulus
If Err Then Exit Function
Next
End If
Crypt = lLngResult
End Function
Public Function Encode(ByVal pStrMessage)
Dim lLngIndex
Dim lLngMaxIndex
Dim lBytAscii
Dim lLngEncrypted
lLngMaxIndex = Len(pStrMessage)
If lLngMaxIndex = 0 Then Exit Function
For lLngIndex = 1 To lLngMaxIndex
lBytAscii = Asc(Mid(pStrMessage, lLngIndex, 1))
lLngEncrypted = Crypt(lBytAscii, PublicKey)
Encode = Encode & NumberToHex(lLngEncrypted, 4)
Next
End Function
Public Function Decode(ByVal pStrMessage)
Dim lBytAscii
Dim lLngIndex
Dim lLngMaxIndex
Dim lLngEncryptedData
Decode = ""
lLngMaxIndex = Len(pStrMessage)
For lLngIndex = 1 To lLngMaxIndex Step 4
lLngEncryptedData = HexToNumber(Mid(pStrMessage, lLngIndex, 4))
lBytAscii = Crypt(lLngEncryptedData, PrivateKey)
Decode = Decode & Chr(lBytAscii)
Next
End Function
Private Function NumberToHex(ByRef pLngNumber, ByRef pLngLength)
NumberToHex = Right(String(pLngLength, "0") & Hex(pLngNumber), pLngLength)
End Function
Private Function HexToNumber(ByRef pStrHex)
HexToNumber = CLng("&h" & pStrHex)
End Function
End Class
%>
test.asp
<!--#INCLUDE FILE="RSA.asp"-->
<%
function Encryptstr(Message)
Dim LngKeyE
Dim LngKeyD
Dim LngKeyN
Dim StrMessage
Dim ObjRSA
LngKeyE = "32823"
LngKeyD = "20643"
LngKeyN = "29893"
StrMessage = Message
Set ObjRSA = New clsRSA
ObjRSA.PublicKey = LngKeyE
ObjRSA.Modulus = LngKeyN
Encryptstr = ObjRSA.Encode(StrMessage)
Set ObjRSA = Nothing
end function
function decryptstr(Message)
Dim LngKeyE
Dim LngKeyD
Dim LngKeyN
Dim StrMessage
Dim ObjRSA
LngKeyE = "32823"
LngKeyD = "20643"
LngKeyN = "29893"
StrMessage = Message
Set ObjRSA = New clsRSA
ObjRSA.PrivateKey =LngKeyD
ObjRSA.Modulus=LngKeyN
decryptstr=ObjRSA.Decode(StrMessage)
Set ObjRSA = Nothing
end function
dim last,first
first="sohu"
Response.Write "加密前為:"&first
last=Encryptstr(first)
Response.Write "加密后為"&last
Response.Write "解密后為" &decryptstr(last)
%>
一段在asp中加密與解密對(duì)應(yīng)的函數(shù)
如何用asp進(jìn)行base64加密
<%
OPTION EXPLICIT
const BASE_64_MAP_INIT =
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"
dim nl
’ zero based arrays
dim Base64EncMap(63)
dim Base64DecMap(127)
’ must be called before using anything else
PUBLIC SUB initCodecs()
’ init vars
nl = "<P>" & chr(13) & chr(10)
’ setup base 64
dim max, idx
max = len(BASE_64_MAP_INIT)
for idx = 0 to max - 1
’ one based string
Base64EncMap(idx) = mid(BASE_64_MAP_INIT, idx + 1, 1)
next
for idx = 0 to max - 1
Base64DecMap(ASC(Base64EncMap(idx))) = idx
next
END SUB
’ encode base 64 encoded string
PUBLIC FUNCTION base64Encode(plain)
if len(plain) = 0 then
base64Encode = ""
exit function
end if
dim ret, ndx, by3, first, second, third
by3 = (len(plain) \ 3) * 3
ndx = 1
do while ndx <= by3
first = asc(mid(plain, ndx+0, 1))
second = asc(mid(plain, ndx+1, 1))
third = asc(mid(plain, ndx+2, 1))
ret = ret & Base64EncMap( (first \ 4) AND 63 )
ret = ret & Base64EncMap( ((first * 16) AND 48) + ((second \ 16)
AND 15 ) )
ret = ret & Base64EncMap( ((second * 4) AND 60) + ((third \ 64)
AND 3 ) )
ret = ret & Base64EncMap( third AND 63)
ndx = ndx + 3
loop
’ check for stragglers
if by3 < len(plain) then
first = asc(mid(plain, ndx+0, 1))
ret = ret & Base64EncMap( (first \ 4) AND 63 )
if (len(plain) MOD 3 ) = 2 then
second = asc(mid(plain, ndx+1, 1))
ret = ret & Base64EncMap( ((first * 16) AND 48) +
((second 16) AND 15 ) )
ret = ret & Base64EncMap( ((second * 4) AND 60) )
else
ret = ret & Base64EncMap( (first * 16) AND 48)
ret = ret & "="
end if
ret = ret & "="
end if
base64Encode = ret
END FUNCTION
’ decode base 64 encoded string
PUBLIC FUNCTION base64Decode(scrambled)
if len(scrambled) = 0 then
base64Decode = ""
exit function
end if
’ ignore padding
dim realLen
realLen = len(scrambled)
do while mid(scrambled, realLen, 1) = "="
realLen = realLen - 1
loop
dim ret, ndx, by4, first, second, third, fourth
ret = ""
by4 = (realLen \ 4) * 4
ndx = 1
do while ndx <= by4
first = Base64DecMap(asc(mid(scrambled, ndx+0, 1)))
second = Base64DecMap(asc(mid(scrambled, ndx+1, 1)))
third = Base64DecMap(asc(mid(scrambled, ndx+2, 1)))
fourth = Base64DecMap(asc(mid(scrambled, ndx+3, 1)))
ret = ret & chr( ((first * 4) AND 255) + ((second \ 16) AND 3)
)
ret = ret & chr( ((second * 16) AND 255) + ((third \ 4) AND
15) )
ret = ret & chr( ((third * 64) AND 255) + (fourth AND 63) )
ndx = ndx + 4
loop
&nb, sp; ’ check for stragglers, will be 2 or 3 characters
if ndx < realLen then
first = Base64DecMap(asc(mid(scrambled, ndx+0, 1)))
second = Base64DecMap(asc(mid(scrambled, ndx+1, 1)))
ret = ret & chr( ((first * 4) AND 255) + ((second \ 16) AND 3)
)
if realLen MOD 4 = 3 then
third = Base64DecMap(asc(mid(scrambled,ndx+2,1)))
ret = ret & chr( ((second * 16) AND 255) + ((third \ 4) AND
15) )
end if
end if
base64Decode = ret
END FUNCTION
’ initialize
call initCodecs
’ Testing code
’ dim inp, encode
’ inp = request.QueryString("input")
’ encode = base64Encode(inp)
’ response.write "Encoded value = " & encode & nl
’ response.write "Decoded value = " & base64Decode(encode) & nl
%>
用asp寫(xiě)個(gè)簡(jiǎn)單的加密和解密的類(lèi)
http://www.pconline.com.cn/pcedu/empolder/wz/asp/0412/509728.html
用asp寫(xiě)個(gè)簡(jiǎn)單的加密和解密的類(lèi),在這個(gè)類(lèi)中簡(jiǎn)單的實(shí)現(xiàn)了一個(gè)加密和解密。目的是和大家分享一下。這個(gè)類(lèi)的破解非常簡(jiǎn)單?纯次业淖⑨尵椭朗窃趺椿厥铝。下次編寫(xiě)一個(gè)java的加密和解密的類(lèi)。
class Base64Class
rem Const
dim sBASE_64_CHARACTERS’轉(zhuǎn)化碼
dim lenString ’計(jì)算字符串的長(zhǎng)度
dim iCount ’計(jì)數(shù)器
dim returnvalue ’返回值
dim tempChar’緩存字符
dim tempString’緩存字符串
dim paramString ’參數(shù)字符串
dim temHex’緩存緩存十六進(jìn)制
dim tempLow’緩存低位
dim tempHigh’緩存高位
dim mod3String’
dim mod4String’
dim tempBinary’
dim tempByteOne’
dim tempByteTwo’
dim tempByteThree’
dim tempByteFour’
dim tempSaveBitsOne’
dim tempSaveBitsTwo’
’********************************************
’begin初始化類(lèi)
’********************************************
private sub Class_Initialize()
sBASE_64_CHARACTERS = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/" end sub
’********************************************
’end初始化類(lèi) ’
********************************************
’********************************************
’begin銷(xiāo)毀類(lèi)
’********************************************
Private Sub Class_Terminate()
sBASE_64_CHARACTERS="" end sub
’********************************************
’end銷(xiāo)毀類(lèi)
’********************************************
’********************************************
’begin將Ansi編碼的字符串進(jìn)行Base64編碼
’********************************************
public function Encode(paramString)
tempString=""
returnvalue=""
lenString=len(paramString)
if lenString<1 then
Encode=returnvalue
else
mod3String=lenString mod 3
’補(bǔ)足位數(shù)是為了便于計(jì)算
if mod3String>0 then
lenString=lenString+3-mod3String
lenString=lenString-3
end if
’*************************begin
for iCount=1 to lenString step 3
tempBinary = Mid(paramString, iCount, 3)
’response.write tempBinary
tempByteOne= Asc(Mid(tempBinary, 1, 1)): tempSaveBitsOne = tempByteOne And 3
tempByteTwo = Asc(Mid(tempBinary, 2, 1)): tempSaveBitsTwo = tempByteTwo And 15
tempChar = Asc(Mid(tempBinary, 3, 1))
tempByteOne = Mid(sBASE_64_CHARACTERS, ((tempByteOne And 252) \ 4) + 1, 1)
tempByteTwo = Mid(sBASE_64_CHARACTERS, (((tempByteTwo And 240) \ 16) Or (tempSaveBitsOne * 16) And &HFF) + 1, 1)
tempByteThree = Mid(sBASE_64_CHARACTERS, (((tempChar And 192) \ 64) Or (tempSaveBitsTwo * 4) And &HFF) + 1, 1)
tempByteFour = Mid(sBASE_64_CHARACTERS, (tempChar And 63) + 1, 1)
tempString = tempByteOne & tempByteTwo & tempByteThree & tempByteFour returnvalue=returnvalue & tempString next
’*************************end
’*************************begin處理最后剩余的幾個(gè)字符
if mod3String>0 then
tempBinary = Mid(paramString, iCount, mod3String)
if mod3String=1 then
tempString = tempBinary & Chr(64) & Chr(64) & Chr(64) ’用@號(hào)補(bǔ)足位數(shù)
else tempString = tempBinary & Chr(64) & Chr(64) ’用@號(hào)補(bǔ)足位數(shù)
end if
returnvalue=returnvalue & tempString
end if
’*************************end處理最后剩余的幾個(gè)字符
Encode=returnvalue end if end function
’********************************************
’end將Ansi編碼的字符串進(jìn)行Base64編碼
’********************************************
’********************************************
’end將Base64編碼字符串轉(zhuǎn)換成Ansi編碼的字符串
’********************************************
public function Decode(paramString)
tempString=""
returnvalue=""
lenString=len(paramString)
if lenString<1 then
Decode=returnvalue
else
mod4String=lenString mod 4
if mod4String >0 then ’字符串長(zhǎng)度應(yīng)當(dāng)是4的倍數(shù)
Decode=returnvalue
else ’begin判斷是不是@號(hào)
if Mid(paramString, lenString-1, 1) = "@" then
mod4String=2
end if
if Mid(paramString, lenString-2, 1) = "@" then
mod4String=1
end if
’end判斷是不是@號(hào)
if mod4String>0 then
lenString=lenString-4
end if
’******************************begin
for iCount=1 to lenString step 4
tempString = Mid(paramString, iCount, 4)
tempByteOne = InStr(sBASE_64_CHARACTERS, Mid(tempString, 1, 1)) - 1
tempByteTwo = InStr(sBASE_64_CHARACTERS, Mid(tempString, 2, 1)) - 1
tempByteThree = InStr(sBASE_64_CHARACTERS, Mid(tempString, 3, 1)) - 1
tempByteFour = InStr(sBASE_64_CHARACTERS, Mid(tempString, 4, 1)) - 1
tempByteOne = Chr(((tempByteTwo And 48) \ 16) Or (tempByteOne * 4) And &HFF) tempByteTwo = "" & Chr(((tempByteThree And 60) \ 4) Or (tempByteTwo * 16) And &HFF)
tempByteThree = Chr((((tempByteThree And 3) * 64) And &HFF) Or (tempByteFour And 63))
tempString=tempByteOne & tempByteTwo & tempByteThree
returnvalue=returnvalue & tempString
next
’******************************end
’處理最后剩余的幾個(gè)字符
if mod4String > 0 then
tempString=left(right(paramString,4),mod4String)
returnvalue = returnvalue & tempString
end if
Decode=returnvalue
end if
end if
end function
’********************************************
’end將Base64編碼字符串轉(zhuǎn)換成Ansi編碼的字符串
’********************************************
end class
ASP中時(shí)間函數(shù)的使用(一)
副標(biāo)題:
作者:佚名 文章來(lái)源:本站原創(chuàng) 點(diǎn)擊數(shù):313 更新時(shí)間:2004-9-16
Date 函數(shù)
描述:返回當(dāng)前系統(tǒng)日期。
語(yǔ)法:Date
DateAdd 函數(shù)
描述:返回已添加指定時(shí)間間隔的日期。
語(yǔ)法:DateAdd(interval, number, date)
interval: 必選。字符串表達(dá)式,表示要添加的時(shí)間間隔。有關(guān)數(shù)值,請(qǐng)參閱“設(shè)置”部分。
number: 必選。數(shù)值表達(dá)式,表示要添加的時(shí)間間隔的個(gè)數(shù)。數(shù)值表達(dá)式可以是正數(shù)(得到未來(lái)的日期)或負(fù)數(shù)(得到過(guò)去的日期)。
date: 必選。Variant 或要添加 interval 的表示日期的文字。
interval 參數(shù)可以有以下值:
yyyy (年) 、q (季度) 、m (月) 、y (一年的日數(shù)) 、d (日) 、w (一周的日數(shù)) 、ww (周) 、h (小時(shí)) 、n (分鐘) 、s (秒)
說(shuō)明:可用 DateAdd 函數(shù)從日期中添加或減去指定時(shí)間間隔。例如可以使用 DateAdd 從當(dāng)天算起 30 天以后的日期或從現(xiàn)在算起 45 分鐘以后的時(shí)間。要向 date 添加以“日”為單位的時(shí)間間隔,可以使用“一年的日數(shù)”(“y”)、“日”(“d”)或“一周的日數(shù)”(“w”)。
DateAdd 函數(shù)不會(huì)返回?zé)o效日期。如下示例將 95 年 1 月 31 日加上一個(gè)月:
NewDate = DateAdd("m", 1, "31-Jan-95")
在這個(gè)例子中,DateAdd 返回 95 年 2 月 28 日,而不是 95 年 2 月 31 日。如果 date 為 96 年 1 月 31 日,則返回 96 年 2 月 29 日,這是因?yàn)?nbsp;1996 是閏年。
如果計(jì)算的日期是在公元 100 年之前則會(huì)產(chǎn)生錯(cuò)誤。
如果 number 不是 Long 型值,則在計(jì)算前四舍五入為最接近的整數(shù)。
DateDiff 函數(shù)
描述:返回兩個(gè)日期之間的時(shí)間間隔。
語(yǔ)法:DateDiff(interval, date1, date2 [,firstdayofweek[, firstweekofyear>)
interval: 必選。字符串表達(dá)式,表示用于計(jì)算 date1 和 date2 之間的時(shí)間間隔。有關(guān)數(shù)值,請(qǐng)參閱“設(shè)置”部分。
date1, date2: 必選。日期表達(dá)式。用于計(jì)算的兩個(gè)日期。
firstdayofweek: 可選。指定星期中第一天的常數(shù)。如果沒(méi)有指定,則默認(rèn)為星期日。有關(guān)數(shù)值,請(qǐng)參閱“設(shè)置”部分。
firstweekofyear: 可選。指定一年中第一周的常數(shù)。如果沒(méi)有指定,則默認(rèn)為 1 月 1 日所在的星期。有關(guān)數(shù)值,請(qǐng)參閱“設(shè)置”部分。
interval 參數(shù)可以有以下值:
yyyy (年) 、q (季度) 、m (月) 、y (一年的日數(shù)) 、d (日) 、w (一周的日數(shù)) 、ww (周) 、h (小時(shí)) 、n (分鐘) 、s (秒)
firstdayofweek 參數(shù)可以有以下值:
(以下分別為:常數(shù) 值 描述)
vbUseSystem 0 使用區(qū)域語(yǔ)言支持 (NLS) API 設(shè)置。
vbSunday 1 星期日(默認(rèn))
vbMonday 2 星期一
vbTuesday 3 星期二
vbWednesday 4 星期三
vbThursday 5 星期四
vbFriday 6 星期五
vbSaturday 7 星期六
firstweekofyear 參數(shù)可以有以下值:
(以下分別為:常數(shù) 值 描述)
vbUseSystem 0 使用區(qū)域語(yǔ)言支持 (NLS) API 設(shè)置。
vbFirstJan1 1 由 1 月 1 日所在的星期開(kāi)始(默認(rèn))。
vbFirstFourDays 2 由在新年中至少有四天的第一周開(kāi)始。
vbFirstFullWeek 3 由在新的一年中第一個(gè)完整的周開(kāi)始。
說(shuō)明:DateDiff 函數(shù)用于判斷在兩個(gè)日期之間存在的指定時(shí)間間隔的數(shù)目。例如可以使用 DateDiff 計(jì)算兩個(gè)日期相差的天數(shù),或者當(dāng)天到當(dāng)年最后一天之間的星期數(shù)。
要計(jì)算 date1 和 date2 相差的天數(shù),可以使用“一年的日數(shù)”(“y”)或“日”(“d”)。當(dāng) interval 為“一周的日數(shù)”(“w”)時(shí),DateDiff 返回兩個(gè)日期之間的星期數(shù)。如果 date1 是星期一,則 DateDiff 計(jì)算到 date2 之前星期一的數(shù)目。此結(jié)果包含 date2 而不包含 date1。如果 interval 是“周”(“ww”),則 DateDiff 函數(shù)返回日歷表中兩個(gè)日期之間的星期數(shù)。函數(shù)計(jì)算 date1 和 date2 之間星期日的數(shù)目。如果 date2 是星期日,DateDiff 將計(jì)算 date2,但即使 date1 是星期日,也不會(huì)計(jì)算 date1。
如果 date1 晚于 date2,則 DateDiff 函數(shù)返回負(fù)數(shù)。
firstdayofweek 參數(shù)會(huì)對(duì)使用“w”和“ww”間隔符號(hào)的計(jì)算產(chǎn)生影響。
如果 date1 或 date2 是日期文字,則指定的年度會(huì)成為日期的固定部分。但是如果 date1 或 date2 被包括在引號(hào) (" ") 中并且省略年份,則在代碼中每次計(jì)算 date1 或 date2 表達(dá)式時(shí),將插入當(dāng)前年份。這樣就可以編寫(xiě)適用于不同年份的程序代碼。
在 interval 為“年”(“yyyy”)時(shí),比較 12 月 31 日和來(lái)年的 1 月 1 日,雖然實(shí)際上只相差一天,DateDiff 返回 1 表示相差一個(gè)年份。
DatePart 函數(shù)
描述:返回給定日期的指定部分。
語(yǔ)法:DatePart(interval, date[, firstdayofweek[, firstweekofyear>)
DatePart: 函數(shù)的語(yǔ)法有以下參數(shù):
interval: 必選。字符串表達(dá)式,表示要返回的時(shí)間間隔。有關(guān)數(shù)值,請(qǐng)參閱“設(shè)置”部分。
date: 必選。要計(jì)算的日期表達(dá)式。
firstdayof week: 可選。指定星期中的第一天的常數(shù)。如果沒(méi)有指定,則默認(rèn)為星期日。有關(guān)數(shù)值,請(qǐng)參閱“設(shè)置”部分。
firstweekofyear: 可選。指定一年中第一周的常數(shù)。如果沒(méi)有指定,則默認(rèn)為 1 月 1 日所在的星期。有關(guān)數(shù)值,請(qǐng)參閱“設(shè)置”部分。
interval 參數(shù)可以有以下值:
yyyy (年) 、q (季度) 、m (月) 、y (一年的日數(shù)) 、d (日) 、w (一周的日數(shù)) 、ww (周) 、h (小時(shí)) 、n (分鐘) 、s (秒)
firstdayofweek 參數(shù)可以有以下值:
(以下分別為:常數(shù) 值 描述)
vbUseSystem 0 使用區(qū)域語(yǔ)言支持 (NLS) API 設(shè)置。
vbSunday 1 星期日(默認(rèn))
vbMonday 2 星期一
vbTuesday 3 星期二
vbWednesday 4 星期三
vbThursday 5 星期四
vbFriday 6 星期五
vbSaturday 7 星期六
firstweekofyear 參數(shù)可以有以下值:
(以下分別為:常數(shù) 值 描述)
vbUseSystem 0 使用區(qū)域語(yǔ)言支持 (NLS) API 設(shè)置。
vbFirstJan1 1 由 1 月 1 日所在的星期開(kāi)始(默認(rèn))。
vbFirstFourDays 2 由在新年中至少有四天的第一周開(kāi)始。
vbFirstFullWeek 3 由在新的一年中第一個(gè)完整的周(不跨年度)開(kāi)始。
說(shuō)明:DatePart 函數(shù)用于計(jì)算日期并返回指定的時(shí)間間隔。例如使用 DatePart 計(jì)算某一天是星期幾或當(dāng)前的時(shí)間。
firstdayofweek 參數(shù)會(huì)影響使用“w”和“ww”間隔符號(hào)的計(jì)算。
如果 date 是日期文字,則指定的年度會(huì)成為日期的固定部分。但是如果 date 被包含在引號(hào) (" ") 中,并且省略年份,則在代碼中每次計(jì)算 date 表達(dá)式時(shí),將插入當(dāng)前年份。這樣就可以編寫(xiě)適用于不同年份的程序代碼。
ASP中時(shí)間函數(shù)的使用(二)
副標(biāo)題:
作者:佚名 文章來(lái)源:本站原創(chuàng) 點(diǎn)擊數(shù):232 更新時(shí)間:2004-9-16
DateSerial 函數(shù)
描述:對(duì)于指定的年、月、日,返回 Date 子類(lèi)型的 Variant。
語(yǔ)法:DateSerial(year, month, day)
year: 從 100 到 9999 之間的數(shù)字或數(shù)值表達(dá)式。
month: 任意數(shù)值表達(dá)式。
day: 任意數(shù)值表達(dá)式。
說(shuō)明:要指定日期,如 1991 年 12 月 31 日,DateSerial 函數(shù)中每個(gè)參數(shù)的取值范圍都應(yīng)該是可接受的;即日的取值應(yīng)在 1 和 31 之間,月的取值應(yīng)在 1 和 12 之間。但是,也可以使用表示某日之前或之后的年、月、日數(shù)目的數(shù)值表達(dá)式為每個(gè)參數(shù)指定相對(duì)日期。
以下樣例中使用了數(shù)值表達(dá)式代替絕對(duì)日期。在這里,DateSerial 函數(shù)返回 1990 年 8 月 1 日之前十年 (1990 - 10) 零兩個(gè)月 (8 - 2) 又一天 (1 - 1) 的日期:即 1980 年 5 月 31 日。
DateSerial(1990 - 10, 8 - 2, 1 - 1)
對(duì)于 year 參數(shù),若取值范圍是從 0 到 99,則被解釋為 1900 到 1999 年。對(duì)于此范圍之外的 year 參數(shù),則使用四位數(shù)字表示年份(例如 1800 年)。
當(dāng)任何一個(gè)參數(shù)的取值超出可接受的范圍時(shí),則會(huì)適當(dāng)?shù)剡M(jìn)位到下一個(gè)較大的時(shí)間單位。例如,如果指定了 35 天,則這個(gè)天數(shù)被解釋成一個(gè)月加上多出來(lái)的日數(shù),多出來(lái)的日數(shù)取決于其年份和月份。但是如果參數(shù)值超出 -32,768 到 32,767 的范圍,或者由三個(gè)參數(shù)指定(無(wú)論是直接還是通過(guò)表達(dá)式指定)的日期超出了可以接受的日期范圍,就會(huì)發(fā)生錯(cuò)誤。
Datevalue 函數(shù)
描述:返回 Date 子類(lèi)型的 Variant。
語(yǔ)法:Datevalue(date)
date 參數(shù)應(yīng)是字符串表達(dá)式,表示從 100 年 1 月 1 日到 9999 年 12 月 31 日中的一個(gè)日期。但是,date 也可以是表示上述范圍內(nèi)的日期、時(shí)間或日期時(shí)間混合的任意表達(dá)式。
說(shuō)明:如果 date 參數(shù)包含時(shí)間信息,則 Datevalue 不會(huì)返回時(shí)間信息。但是如果 date 包含無(wú)效的時(shí)間信息(如 "89:98"),就會(huì)出現(xiàn)錯(cuò)誤。
如果 date 是某一字符串,其中僅包含由有效的日期分隔符分隔開(kāi)的數(shù)字,則 Datevalue 將會(huì)根據(jù)為系統(tǒng)指定的短日期格式識(shí)別月、日和年的順序。Datevalue 還會(huì)識(shí)別包含月份名稱(無(wú)論是全名還是縮寫(xiě))的明確日期。例如,除了能夠識(shí)別 12/30/1991 和 12/30/91 之外,Datevalue 還能識(shí)別 December 30, 1991 和 Dec 30, 1991。
如果省略了 date 的年份部分,Datevalue 將使用計(jì)算機(jī)系統(tǒng)日期中的當(dāng)前年份。
Day 函數(shù)
描述:返回 1 到 31 之間的一個(gè)整數(shù)(包括 1 和31),代表某月中的一天。
語(yǔ)法:Day(date)
date 參數(shù)是任意可以代表日期的表達(dá)式。如果 date 參數(shù)中包含 Null,則返回 Null。
FormatDateTime 函數(shù)
描述:返回表達(dá)式,此表達(dá)式已被格式化為日期或時(shí)間。
語(yǔ)法:FormatDateTime(Date[,NamedFormat])
Date: 必選。要被格式化的日期表達(dá)式。
NamedFormat: 可選。指示所使用的日期/時(shí)間格式的數(shù)值,如果省略,則使用 vbGeneralDate。
NamedFormat 參數(shù)可以有以下值:
(以下分別為:常數(shù) 值 描述)
vbGeneralDate 0 顯示日期和/或時(shí)間。如果有日期部分,則將該部分顯示為短日期格式。如果有時(shí)間部分,則將該部分顯示為長(zhǎng)時(shí)間格式。如果都存在,則顯示所有部分。
vbLongDate 1 使用計(jì)算機(jī)區(qū)域設(shè)置中指定的長(zhǎng)日期格式顯示日期。
vbShortDate 2 使用計(jì)算機(jī)區(qū)域設(shè)置中指定的短日期格式顯示日期。
vbLongTime 3 使用計(jì)算機(jī)區(qū)域設(shè)置中指定的時(shí)間格式顯示時(shí)間。
vbShortTime 4 使用 24 小時(shí)格式 (hh:mm) 顯示時(shí)間。
Hour 函數(shù)
描述:返回 0 到 23 之間的一個(gè)整數(shù)(包括 0 和 23),代表一天中的某一小時(shí)。
語(yǔ)法:Hour(time)
time 參數(shù)是任意可以代表時(shí)間的表達(dá)式。如果 time 參數(shù)中包含 Null,則返回 Null。
Minute 函數(shù)
描述:返回 0 到 59 之間的一個(gè)整數(shù)(包括 0 和59),代表一小時(shí)內(nèi)的某一分鐘。
語(yǔ)法:Minute(time)
time 參數(shù)是任意可以代表時(shí)間的表達(dá)式。如果 time 參數(shù)包含 Null,則返回 Null。
Month 函數(shù)
描述:返回 1 到 12 之間的一個(gè)整數(shù)(包括 1 和 12),代表一年中的某月。
語(yǔ)法:Month(date)
date 參數(shù)是任意可以代表日期的表達(dá)式。如果 date 參數(shù)中包含 Null,則返回 Null。
ASP中時(shí)間函數(shù)的使用(三)
副標(biāo)題:
作者:佚名 文章來(lái)源:本站原創(chuàng) 點(diǎn)擊數(shù):150 更新時(shí)間:2004-9-16
MonthName 函數(shù)
描述:返回表明指定月份的字符串。
語(yǔ)法:MonthName(month[, abbreviate])
month: 必選。月份的數(shù)值定義。例如,一月是 1,二月是 2,以此類(lèi)推。
abbreviate: 可選。Boolean 值,表明月份名稱是否簡(jiǎn)寫(xiě)。如果省略,默認(rèn)值為 False,即不簡(jiǎn)寫(xiě)月份名稱。
Now 函數(shù)
描述:根據(jù)計(jì)算機(jī)系統(tǒng)設(shè)定的日期和時(shí)間返回當(dāng)前的日期和時(shí)間值。
語(yǔ)法:Now
Second 函數(shù)
描述:返回 0 到 59 之間的一個(gè)整數(shù)(包括 1 和 59),代表一分鐘內(nèi)的某一秒。
語(yǔ)法:Second(time)
time 參數(shù)是任意可以代表時(shí)間的表達(dá)式。如果 time 參數(shù)中包含 Null,則返回 Null。
Time 函數(shù)
描述:返回 Date 子類(lèi)型 Variant,指示當(dāng)前系統(tǒng)時(shí)間。
語(yǔ)法:Time
TimeSerial 函數(shù)
描述:返回一個(gè) Date 子類(lèi)型的 Variant,含有指定時(shí)、分、秒的時(shí)間。
語(yǔ)法:TimeSerial(hour, minute, second)
hour: 其值為從 0 (12:00 A.M.) 到 23 (11:00 P.M.) 的數(shù)值或數(shù)值表達(dá)式。
minute: 任意數(shù)值表達(dá)式。
second: 任意數(shù)值表達(dá)式。
說(shuō)明:要指定一時(shí)刻,如 11:59:59,TimeSerial 的參數(shù)取值應(yīng)在可接受的范圍內(nèi);也就是說(shuō),小時(shí)應(yīng)介于 0-23 之間,分和秒應(yīng)介于 0-59 之間。但是,可以使用數(shù)值表達(dá)式為每個(gè)參數(shù)指定相對(duì)時(shí)間,這一表達(dá)式代表某時(shí)刻之前或之后的時(shí)、分或秒數(shù)。以下樣例中使用了表達(dá)式代替絕對(duì)時(shí)間數(shù)。TimeSerial 函數(shù)返回中午之前六小時(shí) (12 - 6) 十五分鐘的時(shí)間 (-15),即 5:45:00 A.M.。
TimeSerial(12 - 6, -15, 0)
當(dāng)任何一個(gè)參數(shù)的取值超出可接受的范圍時(shí),它會(huì)正確地進(jìn)位到下一個(gè)較大的時(shí)間單位中。例如,如果指定了 75 分鐘,則這個(gè)時(shí)間被解釋成一小時(shí)十五分鐘。但是,如果任何一個(gè)參數(shù)值超出 -32768 到 32767 的范圍,就會(huì)導(dǎo)致錯(cuò)誤。如果使用三個(gè)參數(shù)直接指定的時(shí)間或通過(guò)表達(dá)式計(jì)算出的時(shí)間超出可接受的日期范圍,也會(huì)導(dǎo)致錯(cuò)誤。
Timevalue 函數(shù)
描述:返回包含時(shí)間的 Date 子類(lèi)型的 Variant。
語(yǔ)法:Timevalue(time)
time 參數(shù)通常是代表從 0:00:00 (12:00:00 A.M.) 到 23:59:59 (11:59:59 P.M.) 的字符串表達(dá)式(包括 0:00:00 和 23:59:59)。不過(guò),time 也可以是代表該范圍內(nèi)任何時(shí)間的表達(dá)式。如果 time 參數(shù)包含 Null,則返回 Null。
說(shuō)明:可以采用 12 或 24 小時(shí)時(shí)鐘格式輸入時(shí)間。例如 "2:24PM" 和 "14:24" 都是有效的 time 參數(shù)。
如果 time 參數(shù)包含日期信息, Timevalue 函數(shù)并不返回日期信息。然而,如果 time 參數(shù)包含無(wú)效的日期信息,則會(huì)出現(xiàn)錯(cuò)誤。
Weekday 函數(shù)
描述:返回代表一星期中某天的整數(shù)。
語(yǔ)法:Weekday(date, [firstdayofweek])
date: 可以代表日期的任意表達(dá)式。如果 date 參數(shù)中包含 Null,則返回 Null。
firstdayofweek: 指定星期中第一天的常數(shù)。如果省略,默認(rèn)使用 vbSunday。
firstdayofweek 參數(shù)有如下設(shè)置:
(以下分別為:常數(shù) 值 描述)
vbUseSystem 0 使用區(qū)域語(yǔ)言支持 (NLS) API 設(shè)置。
vbSunday 1 星期日
vbMonday 2 星期一
vbTuesday 3 星期二
vbWednesday 4 星期三
vbThursday 5 星期四
vbFriday 6 星期五
vbSaturday 7 星期六
Weekday 函數(shù)返回如下值:
(以下分別為:常數(shù) 值 描述)
vbSunday 1 星期日
vbMonday 2 星期一
vbTuesday 3 星期二
vbWednesday 4 星期三
vbThursday 5 星期四
vbFriday 6 星期五
vbSaturday 7 星期六
WeekdayName 函數(shù)
描述:返回一個(gè)字符串,表示星期中指定的某一天。
語(yǔ)法:WeekDayName(weekday, abbreviate, firstdayofweek)
weekday: 必選。星期中某天的數(shù)值定義。各天的數(shù)值定義取決于 firstdayofweek 參數(shù)設(shè)置。
abbreviate: 可選。Boolean 值,指明是否縮寫(xiě)表示星期各天的名稱。如果省略, 默認(rèn)值為 False,即不縮寫(xiě)星期各天的名稱。
firstdayofweek: 可選。指明星期第一天的數(shù)值。關(guān)于數(shù)值,請(qǐng)參閱“設(shè)置”部分。
firstdayofweek 參數(shù)有以下值:
(以下分別為:常數(shù) 值 描述)
vbUseSystem 0 使用區(qū)域語(yǔ)言支持 (NLS) API 設(shè)置。
vbSunday 1 星期日(默認(rèn))
vbMonday 2 星期一
vbTuesday 3 星期二
vbWednesday 4 星期三
vbThursday 5 星期四
vbFriday 6 星期五
vbSaturday 7 星期六
Year 函數(shù)
描述:返回一個(gè)代表某年的整數(shù)。
語(yǔ)法:Year(date)
date 參數(shù)是任意可以代表日期的參數(shù)。如果 date 參數(shù)中包含 Null,則返回 Null。
讓我們了解IE的按鈕
副標(biāo)題:
作者:admin 文章來(lái)源:本站原創(chuàng) 點(diǎn)擊數(shù):89 更新時(shí)間:2004-9-11
&nbs, p;
ie按鈕
<OBJECT classid=CLSID:8856F961-340A-11D0-A96B-00C04FD705A2 height=0 id=WebBrowser width=0>
</OBJECT>
<input onclick=document.all.WebBrowser.ExecWB(1,1) type=button value=打開(kāi) name=Button1>
<input onclick=document.all.WebBrowser.ExecWB(4,1) type=button value=另存為 name=Button2>
<input onclick=document.all.WebBrowser.ExecWB(10,1) type=button value=屬性 name=Button3>
<input onclick=document.all.WebBrowser.ExecWB(6,1) type=button value=打印 name=Button>
<input onclick=document.all.WebBrowser.ExecWB(8,1) type=button value=頁(yè)面設(shè)置 name=Button4>
<br>
<input onclick=window.location.reload() type=button value=刷新 name=refresh>
<input onclick="window.external.ImportExportFavorites(true,’’);" type=button value=導(dǎo)入收藏夾 name=Button5>
<input onclick="window.external.ImportExportFavorites(false,’’);" type=button value=導(dǎo)出收藏夾 name=Button32>
<input onclick="window.external.AddFavorite(location.href, document.title)" type=button value=加入收藏夾 name=Button22>
<br>
<input onclick="window.external.ShowBrowserUI(’OrganizeFavorites’, null)" type=button value=整理收藏夾 name=Submit2>
<input onclick=’window.location="view-source:" + window.location.href’ type=button value=查看源文件 name=Button7>
<input onclick="window.external.ShowBrowserUI(’LanguageDialog’, null)" type=button value=語(yǔ)言設(shè)置 name=Button6>
<input onclick=history.go(1) type=submit value=前進(jìn) name=Submit>
<input onclick=history.go(-1) type=submit value=后退 name=Submit2>
要完成此效果把如下代碼加入到<body>區(qū)域中
<input type="button" name="Button" value="點(diǎn)擊保存頁(yè)面" onClick="document.all.WebBrowser.ExecWB(4,1)">
<object id="WebBrowser" width=0 height=0 classid="CLSID:8856F961-340A-11D0-A96B-00C04FD705A2">
</object>
………………………………………………………………………………………………………………………………
鼠標(biāo)自定義
<script language=javascript>var Loaded=false;var Flag=false;</script>
<script src=’ http://files.cometsystems.com/javascript/lc2000.js’
language=javascript></script>
<script language=javascript>if(Loaded&&Flag)TheCometCursor(’cd_electric’,0,626);</script>
要完成此效果把如下代碼加入到<head>區(qū)域中
<SCRIPT LANGUAGE="javascript">
<!-- Begin
var x, y, xold, yold, xdiff, ydiff;
var dir = Array();
dir[0] = "n-resize";
dir[1]="ne-resize";
dir[2]="e-resize";
dir[3]="se-resize";
dir[4] = "s-resize";
dir[5]="sw-resize";
dir[6]="w-resize";
dir[7]="nw-resize";
document.onmousemove = FindXY;
function display(direction) {
document.body.style.cursor = dir[direction];
}
function FindXY(loc) {
x = (document.layers) ? loc.pageX : event.clientX;
y = (document.layers) ? loc.pageY : event.clientY;
xdiff = x - xold;
ydiff = y - yold
if ((xdiff < 2) && (ydiff < -2)) display(0);
if ((xdiff < 2) && (ydiff > 2)) display(4);
if ((xdiff > 2) && (ydiff < 2)) display(2);
if ((xdiff < -2) && (ydiff < 2)) display(6);
if ((xdiff > 2) && (ydiff > 2)) display(3);
if ((xdiff > 2) && (ydiff < -2)) display(1);
if ((xdiff < -2) && (ydiff > 2)) display(5);
if ((xdiff < -2) && (ydiff < -2)) display(7);
xold = x;
yold = y;
}
// End -->
</script>
從一個(gè)Blog中分離出來(lái)的好代碼 [ 日期:2005-06-07 ] [ 來(lái)自: ]/**********************************************************************
*
* 從一個(gè)Blog中分離出來(lái)的好代碼
*
* 如果需要更多代碼,請(qǐng)到:http://www.relaxlife.net 感覺(jué)好幫我頂!
*
*
*
*********************************************************************/
<%
’//----------日期轉(zhuǎn)換成字符串函數(shù)
Function DateToStr(DateTime,ShowType)
Dim DateMonth,DateDay,DateHour,DateMinute
DateMonth=Month(DateTime)
DateDay=Day(DateTime)
DateHour=Hour(DateTime)
DateMinute=Minute(DateTime)
If Len(DateMonth)<2 Then DateMonth="0"&DateMonth
If Len(DateDay)<2 Then DateDay="0"&DateDay
Select Case ShowType
Case "Y-m-d"
DateToStr=Year(DateTime)&"-"&DateMonth&"-"&DateDay
Case "Y-m-d H:I A"
Dim DateAMPM
If DateHour>12 Then
DateHour=DateHour-12
DateAMPM="PM"
Else
DateHour=DateHour
DateAMPM="AM"
End If
If Len(DateHour)<2 Then DateHour="0"&DateHour
If Len(DateMinute)<2 Then DateMinute="0"&DateMinute
DateToStr=Year(DateTime)&"-"&DateMonth&"-"&DateDay&" "&DateHour&":"&DateMinute&" "&DateAMPM
Case "Y-m-d H:I:S"
Dim DateSecond
DateSecond=Second(DateTime)
If Len(DateHour)<2 Then DateHour="0"&DateHour
If Len(DateMinute)<2 Then DateMinute="0"&DateMinute
If Len(DateSecond)<2 Then DateSecond="0"&DateSecond
DateToStr=Year(DateTime)&"-"&DateMonth&"-"&DateDay&" "&DateHour&":"&DateMinute&":"&DateSecond
Case "YmdHIS"
DateSecond=Second(DateTime)
If Len(DateHour)<2 Then DateHour="0"&DateHour
If Len(DateMinute)<2 Then DateMinute="0"&DateMinute
If Len(DateSecond)<2 Then DateSecond="0"&DateSecond
DateToStr=Year(DateTime)&DateMonth&DateDay&DateHour&DateMinute&DateSecond
Case "ym"
DateToStr=Right(Year(DateTime),2)&DateMonth
Case "d"
DateToStr=DateDay
Case Else
If Len(DateHour)<2 Then DateHour="0"&DateHour
If Len(DateMinute)<2 Then DateMinute="0"&DateMinute
DateToStr=Year(DateTime)&"-"&DateMonth&"-"&DateDay&" "&DateHour&":"&DateMinute
End Select
End Function
’//--------------截取字符串中有前N個(gè)字符。
Function CutStr(byVal Str,byVal StrLen)
Dim l,t,c,i
l=Len(str)
t=0
For i=1 To l
c=AscW(Mid(str,i,1))
If c<0 Or c>255 Then t=t+2 Else t=t+1
IF t>=StrLen Then
CutStr=left(Str,i)&"..."
Exit For
Else
CutStr=Str
End If
Next
End Function
’//--------------隨機(jī)產(chǎn)生N個(gè)字符。
Function Generator(Length)
Dim i, tempS
tempS = "abcdefghijklmnopqrstuvwxyz1234567890"
Generator = ""
If isNumeric(Length) = False Then
Exit Function
End If
For i = 1 to Length
Randomize
Generator = Generator & Mid(tempS,Int((Len(tempS) * Rnd) + 1),1)
Next
End Function
’//-------------過(guò)濾無(wú)效字符
Function CheckStr(byVal ChkStr)
Dim Str:Str=ChkStr
Str=Trim(Str)
If IsNull(Str) Then
CheckStr = ""
Exit Function
End If
Dim re
Set re=new RegExp
re.IgnoreCase =True
re.Global=True
re.Pattern="(\r\n){3,}"
Str=re.Replace(Str,"$1$1$1")
Set re=Nothing
Str = Replace(Str,"’","’’")
Str = Replace(Str, "select", "sele;ct")
Str = Replace(Str, "join", "joi;n")
Str = Replace(Str, "union", "uni;on")
Str = Replace(Str, "where", "whe;re")
Str = Replace(Str, "insert", "inse;rt")
Str = Replace(Str, "delete", "dele;te")
Str = Replace(Str, "update", "upd;ate")
Str = Replace(Str, "like", "like;")
Str = Replace(Str, "drop", "drop;")
Str = Replace(Str, "create", "cre;ate")
Str = Replace(Str, "modify", "modi;fy")
Str = Replace(Str, "rename", "rena;me")
Str = Replace(Str, "alter", "alte;r")
Str = Replace(Str, "cast", "cas;t")
CheckStr=Str
End Function
’//-------------反過(guò)濾無(wú)效字符
Function UnCheckStr(Str)
Str = Replace(Str, "sele;ct", "select")
Str = Replace(Str, "joi;n", "join")
Str = Replace(Str, "uni;on", "union")
Str = Replace(Str, "whe;re", "where")
Str = Replace(Str, "inse;rt", "insert")
Str = Replace(Str, "dele;te", "delete")
Str = Replace(Str, "upd;ate", "update")
Str = Replace(Str, "like;", "like")
Str = Replace(Str, "drop;", "drop")
Str = Replace(Str, "cre;ate", "create")
Str = Replace(Str, "modi;fy", "modify")
Str = Replace(Str, "rena;me", "rename")
Str = Replace(Str, "alte;r", "alter")
Str = Replace(Str, "cas;t", "cast")
UnCheckStr=Str
End Function
’//-----------------------轉(zhuǎn)換HTML代碼
Function HTMLEncode(reString)
Dim Str:Str=reString
If Not IsNull(Str) Then
Str = UnCheckStr(Str)
Str = Replace(Str, "&", "&;")
Str = Replace(Str, ">", ">;")
Str = Replace(Str, "<", "<;")
Str = Replace(Str, CHR(32), " ;")
Str = Replace(Str, CHR(9), " ; ; ; ;")
Str = Replace(Str, CHR(9), " ; ; ; ;")
Str = Replace(Str, CHR(34),"";")
Str = Replace(Str, CHR(39),"’;")
Str = Replace(Str, CHR(13), "")
Str = Replace(Str, CHR(10), "<br>")
HTMLEncode = Str
End If
End Function
’//---------------------------切割前行內(nèi)容
Function SplitLines(byVal Content,byVal ContentNums)
Dim ts,i,l
If IsNull(Content) Then Exit Function
i=1
ts = 0
For i=1 to Len(Content)
l=Mid(Content,i,4)
If l="<br>" Then
ts=ts+1
End If
If ts>ContentNums Then Exit For
Next
If ts>ContentNums Then
Content=Left(Content,i-1)
End If
SplitLines=Content
End Function
’//---------------------------返回時(shí)間差(秒)
Function GetEndTimeNum(StartTime)
GetEndTimeNum = FormatNumber(Timer()-StartTime,6,-1)
End Function
’//------------------------刪除文件
Function DeleteFiles(FilePath)
Dim FSO
Set FSO=Server.CreateObject("Scripting.FileSystemObject")
If Err<>0 Then
Err.Clear
Response.Write("服務(wù)器關(guān)閉FSO,無(wú)法刪除文件")
Else
If FSO.FileExists(FilePath) Then
FSO.DeleteFile FilePath,True
DeleteFiles = 1
Else
DeleteFiles = 0
End If
End If
Set FSO = Nothing
End Function
’//-----------------------查看占用空間
Function GetTotalSize(GetLocal,GetType)
Dim FSO
Set FSO=Server.CreateObject("Scripting.FileSystemObject")
If Err<>0 Then
Err.Clear
GetTotalSize="服務(wù)器關(guān)閉FSO,查看占用空間失敗"
Else
Dim SiteFolder
If GetType="Folder" Then
Set SiteFolder=FSO.GetFolder(GetLocal)
Else
Set SiteFolder=FSO.GetFile(GetLocal)
End If
GetTotalSize=SiteFolder.Size
If GetTotalSize>1024*1024 Then
GetTotalSize=GetTotalSize/1024/1024
If inStr(GetTotalSize,".") Then GetTotalSize = Left(GetTotalSize,inStr(GetTotalSize,".")+2)
GetTotalSize=GetTotalSize&" MB"
Else
GetTotalSize=Fix(GetTotalSize/1024)&" KB"
 , ; End If
Set SiteFolder=Nothing
End If
Set FSO=Nothing
End Function
’//----------------------------復(fù)制文件
Function CopyFiles(TempSource,TempEnd)
Dim FSO
Set FSO = Server.CreateObject("Scripting.FileSystemObject")
If Err<>0 Then
Err.Clear
Response.Write("服務(wù)器關(guān)閉FSO,無(wú)法復(fù)制文件")
Else
If FSO.FileExists(TempEnd) then
Response.Write "目標(biāo)備份文件 <b>" & TempEnd & "</b> 已存在,請(qǐng)先刪除!"
Set FSO=Nothing
Exit Function
End If
If FSO.FileExists(TempSource) Then
Else
Response.Write "要復(fù)制的源數(shù)據(jù)庫(kù)文件 <b>"&TempSource&"</b> 不存在!"
Set FSO=Nothing
Exit Function
End If
FSO.CopyFile TempSource,TempEnd
Response.Write "已經(jīng)成功復(fù)制文件 <b>"&TempSource&"</b> 到 <b>"&TempEnd&"</b>"
End If
Set FSO = Nothing
End Function
’-------------------------------------------------------True/False-------------------------------------
’//----------------檢測(cè)是否有效的E-mail地址
Function IsValidEmail(Email)
Dim names, name, i, c
IsValidEmail = True
Names = Split(email, "@")
If UBound(names) <> 1 Then
IsValidEmail = False
Exit Function
End If
For Each name IN names
If Len(name) <= 0 Then
IsValidEmail = False
Exit Function
End If
For i = 1 to Len(name)
c = Lcase(Mid(name, i, 1))
If InStr("abcdefghijklmnopqrstuvwxyz_-.", c) <= 0 And Not IsNumeric(c) Then
IsValidEmail = false
Exit Function
End If
Next
If Left(name, 1) = "." or Right(name, 1) = "." Then
IsValidEmail = false
Exit Function
End If
Next
If InStr(names(1), ".") <= 0 Then
IsValidEmail = False
Exit Function
End If
i = Len(names(1)) - InStrRev(names(1), ".")
If i <> 2 And i <> 3 Then
IsValidEmail = False
Exit Function
End If
If InStr(email, "..") > 0 Then
IsValidEmail = False
End If
End Function
’//----------------檢測(cè)是否開(kāi)通組件
’FileUp上傳組件:<%=CheckObjInstalled("FileUp.upload")
’FSO文本讀寫(xiě):<%=CheckObjInstalled("Scripting.FileSystemObject")
’數(shù)據(jù)庫(kù)使用:<%=CheckObjInstalled("adodb.connection")
’Jmail組件支持:<%=CheckObjInstalled("JMail.SMTPMail")
’GflSDK組件支持:<%=CheckObjInstalled("GflAx190.GflAx")
’EasyMail郵件支持:<%=CheckObjInstalled("easymail.Mailsend")
’無(wú)組件上傳-ADODB.Stream:<%=CheckObjInstalled("Scripting.Dictionary")
’無(wú)組件上傳-Scripting.Dictionary :<%=CheckObjInstalled("Scripting.Dictionary")
Function CheckObjInstalled(strClassString)
On Error Resume Next
Dim TmpObj
Set TmpObj = Server.CreateObject(strClassString)
If Err = 0 OR Err = -2147221477 Then
CheckObjInstalled= "<font color=""#00FF00""><b>√</b></font>"
ElseIF Err = 1 OR Err = -2147221005 Then
CheckObjInstalled="<font color=""#FF0000""><b>×</b></font>"
End If
Err.Clear
Set TmpObj = Nothing
End Function
’//----------------檢測(cè)用戶名是否是有效的字符
Function IsValidUserName(byVal UserName)
Dim i,c
IsValidUserName = True
For i = 1 To Len(UserName)
c = Lcase(Mid(UserName, i, 1))
IF InStr("$!<>?#^%@~`&*(){};:+=’"" ", c) > 0 Then
IsValidUserName = False
Exit Function
End IF
Next
End Function
’//------------檢測(cè)是否有效的數(shù)字
Function IsInteger(Para)
IsInteger=False
If Not (IsNull(Para) Or Trim(Para)="" Or Not IsNumeric(Para)) Then
IsInteger=True
End If
End Function
’限制上傳文件類(lèi)型
UP_FileType = "RAR,ZIP,SWF,JPG,PNG,GIF,DOC,TXT,CHM,PDF,ACE,JPG,MP3,WMA,WMV,MIDI,AVI,RM,RA,RMVB,MOV,TORRENT"
Function IsvalidFile(File_Type)
IsvalidFile = False
Dim GName
For Each GName in UP_FileType
If File_Type = GName Then
IsvalidFile = True
Exit For
End If
Next
End Function
’---------------------------------------------------------------------------------------------------
’//-------------------本頁(yè)里關(guān)閉Conn對(duì)象,放在最后一行寫(xiě)。
IF TypeName(Conn)<>"Nothing" Then
Conn.Close
Set Conn=Nothing
End IF
’//--------------------------設(shè)置Cookie
Const CookieName="Relaxlife"
Response.Cookies(CookieName)("memName")=memLogin("mem_Name")
Response.Cookies(CookieName)("memPassword")=memLogin("mem_Password")
Response.Cookies(CookieName)("memStatus")=memLogin("mem_Status")
Select Case Request.Form("CookieTime")
Case 1
Response.Cookies(CookieName).Expires=Date+1’保存一天
Case 2
Response.Cookies(CookieName).Expires=Date+31’保存一月
Case 3
Response.Cookies(CookieName).Expires=Date+365’保存一年
End Select
’//--------------------------取Cookie值
memName=CheckStr(Request.Cookies(CookieName)("memName"))
memPassword=CheckStr(Request.Cookies(CookieName)("memPassword"))
memStatus=CheckStr(Request.Cookies(CookieName)("memStatus"))
’//----------------------------3秒后自動(dòng)返回
msg_Content="<a href=’blogview.asp?logID="&blog_ID&"’>評(píng)論發(fā)表成功,點(diǎn)擊返回,或者3秒后自動(dòng)返回</a><meta http-equiv=’refresh’ content=’3;url=blogview.asp?logID="&blog_ID&"’>"
’//-----------------------------------
Reg_Title="錯(cuò)誤信息"
Reg_Message="密碼長(zhǎng)度不符合<br><a href=’javascript:history.go(-1);’>請(qǐng)返回重新輸入</a>"
%>
<table width="95%" border="0" align="center" cellpadding="4" cellspacing="1" bgcolor="#CCCCCC">
<tr><td height="24" align="center"><strong><%=Reg_Title%></strong></td></tr>
<tr><td height="88" align="center" valign="middle" bgcolor="#FFFFFF"><%=Reg_Message%></td></tr>
</table>
<%
’//--------------------------Application的應(yīng)用
’寫(xiě)入表情符號(hào)
Dim Arr_Smilies
IF Not IsArray(Application(CookieName&"_blog_Smilies")) Then
Dim log_SmiliesList
Set log_SmiliesList=Server.CreateObject("ADODB.RecordSet")
SQL="SELECT sm_ID,sm_Image,sm_Text FROM blog_Smilies ORDER BY sm_ID ASC"
log_SmiliesList.Open SQL,Conn,1,1
SQLQueryNums=SQLQueryNums+1
If log_SmiliesList.EOF And log_SmiliesList.BOF Then
Redim Arr_Smilies(3,0)
Else
Arr_Smilies=log_SmiliesList.GetRows
End If
log_SmiliesList.Close
Set log_SmiliesList=Nothing
Application.Lock
Application(CookieName&"_blog_Smilies")=Arr_Smilies
Application.UnLock
Else
Arr_Smilies=Application(CookieName&"_blog_Smilies")
End IF
’//------------------------
If Request.QueryString("type")="EnableSite" Then
Application.Lock()
Application(CookieName & "_SiteEnable") = 1
Application(CookieName & "_SiteDisbleWhy") = ""
Application.UnLock()
Response.Write("<a href=""admincp.asp?action=setting"">開(kāi)啟站點(diǎn)成功,請(qǐng)點(diǎn)擊返回</a>")
ElseIF Request.QueryString("type")="DisableSite" Then
Set Conn=Nothing
FreeApplicationMemory
Application.Lock()
Application(CookieName & "_SiteEnable") = 0
Application(CookieName & "_SiteDisbleWhy")="站點(diǎn)維護(hù)中,請(qǐng)稍候再來(lái)..."
Application.UnLock()
Response.Write("<br><a href=""admincp.asp?action=setting"">關(guān)閉站點(diǎn)成功</a>")
Else
If Application(CookieName & "_SiteEnable") = 0 AND Application(CookieName & "_SiteDisbleWhy")<>"" Then
Response.Write("<b>站點(diǎn)已關(guān)閉</b> ; ; ; ;| ; ; ; ;<a href=""admincp.asp?action=setting&type=EnableSite"">點(diǎn)擊開(kāi)啟站點(diǎn)</a>")
Else
Response.Write("<b>站點(diǎn)已開(kāi)啟</b> ; ; ; ;| ; ; ; ;<a href=""admincp.asp?action=setting&type=DisableSite"">點(diǎn)擊關(guān)閉站點(diǎn)</a>")
End If
End If
’//-----------------------------------釋放網(wǎng)站數(shù)據(jù)列表
Function FreeApplicationMemory
Response.Write "<b>釋放網(wǎng)站數(shù)據(jù)列表:</b>" & VbCrLf
Dim Thing
For Each Thing IN Application.Contents
If Left(Thing,Len(CookieName)) = CookieName Then
Response.Write "<font color=""gray"">" & thing & "</font><br>"
If isObject(Application.Contents(Thing)) Then
Application.Contents(Thing).Close
Set Application.Contents(Thing) = Nothing
Application.Contents(Thing) = Null
Response.Write "成功關(guān)閉對(duì)象"
ElseIF isArray(Application.Contents(Thing)) Then
Set Application.Contents(Thing) = Nothing
Application.Contents(Thing) = Null
Response.Write "成功釋放數(shù)組"
Else
Response.Write(HtmlEncode(Application.Contents(Thing)))
Application.Contents(Thing) = Null
End If
Response.Write(" ; ;")
End If
Next
End Function
’//-----------------------
’定義數(shù)據(jù)庫(kù)鏈接文件,根據(jù)自己的情況修改
Const AccessPath="blogdata"
Const AccessFile="loveyuki.asa"
Const IPAccessFile="ipdata.asa"
’------------定義數(shù)據(jù)庫(kù)連接
Dim Conn
On Error Resume Next
Set Conn= Server.CreateObject("ADODB.Connection")
Conn.ConnectionString="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath(AccessPath&"/"&AccessFile)
Conn.Open
If Err Then
Err.Clear
Set Conn = Nothing
Response.Write("<head><meta http-equiv=""Content-Type"" content=""text/html; charset=utf-8"" /><title>數(shù)據(jù)庫(kù)連接出錯(cuò),請(qǐng)檢查連接字串</title></head><body><div align=""center"" style=""width:400px;height:100px;padding: 8px;font-size:9pt;border: 1px solid ThreeDShadow;POSITION:absolute;top:expression((document.body.offsetHeight-100)/2);left:expression((document.body.offsetWidth-400)/2);""><table width=""100%"" height=""100%"" style=""font-size:12px;font-family:Tahoma;""><tr><td align=""center""><strong>數(shù)據(jù)庫(kù)連接出錯(cuò),請(qǐng)檢查連接字串</strong></td></tr></table></div></body>")
Response.End
End If
’------------壓縮數(shù)據(jù)庫(kù)
Dim FSO,Engine
Set FSO=Server.CreateObject("Scripting.FileSystemObject")
If Err<>0 Then
Err.Clear
Response.Write("服務(wù)器關(guān)閉FSO,無(wú)法壓縮數(shù)據(jù)庫(kù)")
Else
If FSO.FileExists(Server.Mappath(AccessPath&"/"&AccessFile)) Then
Response.Write "壓縮數(shù)據(jù)庫(kù)開(kāi)始,網(wǎng)站暫停一切用戶的前臺(tái)操作......<br>"
Conn.Close
Set Conn=Nothing
Application.Lock
FreeApplicationMemory
Application(CookieName & "_SiteEnable") = 0
Application(CookieName & "_SiteDisbleWhy") = "網(wǎng)站暫停中,請(qǐng)稍候幾分鐘后再來(lái)..."
Application.UnLock
Set Engine = CreateObject("JRO.JetEngine")
Engine.CompactDatabase "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath(AccessPath&"/"&AccessFile), "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.Mappath(AccessPath&"/"&AccessFile&".temp")
FSO.CopyFile Server.Mappath(AccessPath&"/"&AccessFile&".temp"),Server.Mappath(AccessPath&"/"&AccessFile)
FSO.DeleteFile(Server.Mappath(AccessPath&"/"&AccessFile&".temp"))
Set FSO = Nothing
Set Engine = Nothing
Response.write "壓縮數(shù)據(jù)庫(kù)完成..."
Application.Lock
Application(CookieName & "_SiteEnable") = 1
Application(CookieName & "_SiteDisbleWhy") = ""
Application.UnLock
Response.Write "<br>網(wǎng)站恢復(fù)正常訪問(wèn)..."
Response.Write("<br><a href=""admincp.asp?action=database"">請(qǐng)點(diǎn)擊返回</a>")
End If
End If
Set FSO=Nothing
’-----------------------備份數(shù)據(jù)庫(kù)
Response.Write "備份數(shù)據(jù)庫(kù)開(kāi)始,網(wǎng)站暫停一切用戶的前臺(tái)操作......<br>"
Conn.Close
Set Conn=Nothing
Application.Lock
Application(CookieName & "_SiteEnable") = 0
application(CookieName & "_SiteDisbleWhy") = "網(wǎng)站暫停中,請(qǐng)稍候幾分鐘后再來(lái)..."
Application.UnLock
CopyFiles Server.Mappath(AccessPath&"/"&AccessFile),Server.Mappath(AccessPath&"/"&AccessFile & "_" & DateToStr(Now(),"YmdHIS") &".BAK")
Response.write "<br>備份完成..."
Application.Lock
Application(CookieName & "_SiteEnable") = 1
Application(CookieName & "_SiteDisbleWhy") = ""
Application.UnLock
Response.write "<br>網(wǎng)站恢復(fù)正常訪問(wèn)..."
Response.Write("<br><a href=""admincp.asp?action=database"">請(qǐng)點(diǎn)擊返回</a>")
’--------------刪除的文件
If Request.QueryString("filename")=Empty Then
Response.Write("<a href=""admincp.asp?action=database"">要?jiǎng)h除的文件名不能為空,請(qǐng)點(diǎn)擊返回</a>")
Else
If DeleteFiles(Server.MapPath(AccessPath&"/"&Request.QueryString("filename")))=1 Then
Response.Write("<a href=""admincp.asp?action=database"">文件刪除成功,請(qǐng)點(diǎn)擊返回</a>")
Else
Response.Write("<a href=""admincp.asp?action=database"">文件刪除失敗,請(qǐng)點(diǎn)擊返回</a>")
End If
End If
’------------------文件列表
Response.Write("<b>備份文件列表</b><br>")
Dim DataFolder,DataFileList,DataFile,DataFileName
Set FSO=Server.CreateObject("Scripting.FileSystemObject")
If Err<>0 Then
Err.Clear
Response.Write("服務(wù)器關(guān)閉FSO,無(wú)法查看備份文件列表")
Else
Set DataFolder=FSO.GetFolder(Server.MapPath(AccessPath))
Set DataFileList=DataFolder.Files
For Each DataFile IN DataFileList
If Ubound(Split(DataFile,"."))>=2 Then
DataFileName=DataFile.Name
Response.Write("<font color=""#FF0000"">"&DataFileName&"</font> ; ;| ; ;<b><a href=""blogdata/"&DataFileName&""">下載此文件</a></b> ; ;| ; ;<b><a href=""admincp.asp?action=database&type=DeleFile&filename="&DataFileName&""">刪除此文件</a></b> ; ;| ; ;<b><a href=""admincp.asp?action=database&type=Restore&filename="&DataFileName&""">從此文件還原數(shù)據(jù)</a></b><br>")
End If
Next
End If
Set FSO=Nothing
’------------------SQL語(yǔ)句執(zhí)行
Dim SQL_Query
SQL_Query=Request.Form("SQL_Query")
Conn.ExeCute(SQL_Query)
SQLQueryNums=SQLQueryNums+1
Response.Write("<a href=""admincp.asp?action=database"">SQL語(yǔ)句執(zhí)行成功,請(qǐng)點(diǎn)擊返回</a>")
%>
引用通告地址 (0):
http://blog.chenoe.com/blog//trackback.asp?tbID=1797
http://blog.chenoe.com/blog//trackback.asp?tbID=1797&CP=GBK
base64編碼、解碼函數(shù)
http://www.3pcode.com/article/article_3/1858.htm
這是我看完幾個(gè)base64編碼、解碼函數(shù)后自己改寫(xiě)的。
因?yàn),在中文操作系統(tǒng)的VBscript中,使用的是unicode字符集,所以
很多base64編碼、解碼函數(shù)在理論上是正確的,但實(shí)際不能運(yùn)行!
我加寫(xiě)了幾個(gè)Unicode與Ansi編碼轉(zhuǎn)換的函數(shù),現(xiàn)貼出來(lái),請(qǐng)大家執(zhí)教!
文件名稱base64test.asp
<%
sBASE_64_CHARACTERS = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"
sBASE_64_CHARACTERS = strUnicode2Ansi(sBASE_64_CHARACTERS)
Function strUnicodeLen(asContents)
’計(jì)算unicode字符串的Ansi編碼的長(zhǎng)度
asContents1="a"&asContents
len1=len(asContents1)
k=0
for i=1 to len1
asc1=asc(mid(asContents1,i,1))
if asc1<0 then asc1=65536+asc1
if asc1>255 then
k=k+2
else
k=k+1
end if
next
strUnicodeLen=k-1
End Function
Function strUnicode2Ansi(asContents)
’將Unicode編碼的字符串,轉(zhuǎn)換成Ansi編碼的字符串
strUnicode2Ansi=""
len1=len(asContents)
for i=1 to len1
varchar=mid(asContents,i,1)
varasc=asc(varchar)
if , varasc<0 then varasc=varasc+65536
if varasc>255 then
varHex=Hex(varasc)
varlow=left(varHex,2)
varhigh=right(varHex,2)
strUnicode2Ansi=strUnicode2Ansi & chrb("&H" & varlow ) & chrb("&H" & varhigh )
else
strUnicode2Ansi=strUnicode2Ansi & chrb(varasc)
end if
next
End function
Function strAnsi2Unicode(asContents)
’將Ansi編碼的字符串,轉(zhuǎn)換成Unicode編碼的字符串
strAnsi2Unicode = ""
len1=lenb(asContents)
if len1=0 then exit function
for i=1 to len1
varchar=midb(asContents,i,1)
varasc=ascb(varchar)
if varasc > 127 then
strAnsi2Unicode = strAnsi2Unicode & chr(ascw(midb(asContents,i+1,1) & varchar))
i=i+1
else
strAnsi2Unicode = strAnsi2Unicode & chr(varasc)
end if
next
End function
Function Base64encode(asContents)
’將Ansi編碼的字符串進(jìn)行Base64編碼
’asContents應(yīng)當(dāng)是ANSI編碼的字符串(二進(jìn)制的字符串也可以)
Dim lnPosition
Dim lsResult
Dim Char1
Dim Char2
Dim Char3
Dim Char4
Dim Byte1
Dim Byte2
Dim Byte3
Dim SaveBits1
Dim SaveBits2
Dim lsGroupBinary
Dim lsGroup64
Dim m4,len1,len2
len1=Lenb(asContents)
if len1<1 then
Base64encode=""
exit Function
end if
m3=Len1 Mod 3
If M3 > 0 Then asContents = asContents & String(3-M3, chrb(0))
’補(bǔ)足位數(shù)是為了便于計(jì)算
IF m3 > 0 THEN
len1=len1+(3-m3)
len2=len1-3
else
len2=len1
end if
lsResult = ""
For lnPosition = 1 To len2 Step 3
lsGroup64 = ""
lsGroupBinary = Midb(asContents, lnPosition, 3)
Byte1 = Ascb(Midb(lsGroupBinary, 1, 1)): SaveBits1 = Byte1 And 3
Byte2 = Ascb(Midb(lsGroupBinary, 2, 1)): SaveBits2 = Byte2 And 15
Byte3 = Ascb(Midb(lsGroupBinary, 3, 1))
Char1 = Midb(sBASE_64_CHARACTERS, ((Byte1 And 252) \ 4) + 1, 1)
Char2 = Midb(sBASE_64_CHARACTERS, (((Byte2 And 240) \ 16) Or (SaveBits1 * 16) And &HFF) + 1, 1)
Char3 = Midb(sBASE_64_CHARACTERS, (((Byte3 And 192) \ 64) Or (SaveBits2 * 4) And &HFF) + 1, 1)
Char4 = Midb(sBASE_64_CHARACTERS, (Byte3 And 63) + 1, 1)
lsGroup64 = Char1 & Char2 & Char3 & Char4
lsResult = lsResult & lsGroup64
Next
’處理最后剩余的幾個(gè)字符
if M3 > 0 then
lsGroup64 = ""
lsGroupBinary = Midb(asContents, len2+1, 3)
Byte1 = Ascb(Midb(lsGroupBinary, 1, 1)): SaveBits1 = Byte1 And 3
Byte2 = Ascb(Midb(lsGroupBinary, 2, 1)): SaveBits2 = Byte2 And 15
Byte3 = Ascb(Midb(lsGroupBinary, 3, 1))
Char1 = Midb(sBASE_64_CHARACTERS, ((Byte1 And 252) \ 4) + 1, 1)
Char2 = Midb(sBASE_64_CHARACTERS, (((Byte2 And 240) \ 16) Or (SaveBits1 * 16) And &HFF) + 1, 1)
Char3 = Midb(sBASE_64_CHARACTERS, (((Byte3 And 192) \ 64) Or (SaveBits2 * 4) And &HFF) + 1, 1)
if M3=1 then
lsGroup64 = Char1 & Char2 & ChrB(61) & ChrB(61) ’用=號(hào)補(bǔ)足位數(shù)
else
lsGroup64 = Char1 & Char2 & Char3 & ChrB(61) ’用=號(hào)補(bǔ)足位數(shù)
end if
lsResult = lsResult & lsGroup64
end if
Base64encode = lsResult
End Function
Function Base64decode(asContents)
’將Base64編碼字符串轉(zhuǎn)換成Ansi編碼的字符串
’asContents應(yīng)當(dāng)也是ANSI編碼的字符串(二進(jìn)制的字符串也可以)
Dim lsResult
Dim lnPosition
Dim lsGroup64, lsGroupBinary
Dim Char1, Char2, Char3, Char4
Dim Byte1, Byte2, Byte3
Dim M4,len1,len2
len1= Lenb(asContents)
M4 = len1 Mod 4
if len1 < 1 or M4 > 0 then
’字符串長(zhǎng)度應(yīng)當(dāng)是4的倍數(shù)
Base64decode = ""
exit Function
end if
’判斷最后一位是不是 = 號(hào)
’判斷倒數(shù)第二位是不是 = 號(hào)
’這里m4表示最后剩余的需要單獨(dú)處理的字符個(gè)數(shù)
if midb(asContents, len1, 1) = chrb(61) then m4=3
if midb(asContents, len1-1, 1) = chrb(61) then m4=2
if m4 = 0 then
len2=len1
else
len2=len1-4
end if
For lnPosition = 1 To Len2 Step 4
lsGroupBinary = ""
lsGroup64 = Midb(asContents, lnPosition, 4)
Char1 = InStrb(sBASE_64_CHARACTERS, Midb(lsGroup64, 1, 1)) - 1
Char2 = InStrb(sBASE_64_CHARACTERS, Midb(lsGroup64, 2, 1)) - 1
Char3 = InStrb(sBASE_64_CHARACTERS, Midb(lsGroup64, 3, 1)) - 1
Char4 = InStrb(sBASE_64_CHARACTERS, Midb(lsGroup64, 4, 1)) - 1
Byte1 = Chrb(((Char2 And 48) \ 16) Or (Char1 * 4) And &HFF)
Byte2 = lsGroupBinary & Chrb(((Char3 And 60) \ 4) Or (Char2 * 16) And &HFF)
Byte3 = Chrb((((Char3 And 3) * 64) And &HFF) Or (Char4 And 63))
lsGroupBinary = Byte1 & Byte2 & Byte3
lsResult = lsResult & lsGroupBinary
Next
’處理最后剩余的幾個(gè)字符
if M4 > 0 then
lsGroupBinary = ""
lsGroup64 = Midb(asContents, len2+1, m4) & chrB(65) ’chr(65)=A,轉(zhuǎn)換成值為0
if M4=2 then ’補(bǔ)足4位,是為了便于計(jì)算
lsGroup64 = lsGroup64 & chrB(65)
end if
Char1 = InStrb(sBASE_64_CHARACTERS, Midb(lsGroup64, 1, 1)) - 1
Char2 = InStrb(sBASE_64_CHARACTERS, Midb(lsGroup64, 2, 1)) - 1
Char3 = InStrb(sBASE_64_CHARACTERS, Midb(lsGroup64, 3, 1)) - 1
Char4 = InStrb(sBASE_64_CHARACTERS, Midb(lsGroup64, 4, 1)) - 1
Byte1 = Chrb(((Char2 And 48) \ 16) Or (Char1 * 4) And &HFF)
Byte2 = lsGroupBinary & Chrb(((Char3 And 60) \ 4) Or (Char2 * 16) And &HFF)
Byte3 = Chrb((((Char3 And 3) * 64) And &HFF) Or (Char4 And 63))
if M4=2 then
lsGroupBinary = Byte1
elseif M4=3 then
lsGroupBinary = Byte1 & Byte2
end if
lsResult = lsResult & lsGroupBinary
end if
Base64decode = lsResult
End Function |