`

ASP各类常用函数收集整理(转载)

    博客分类:
  • asp
阅读更多
查看文章
   
ASP各类常用函数收集整理
2006-11-02 13:45

获得指定长度的标题名称

' *----------------------------------------------------------------------------
' * 函数:GetString
' * 描述:获得指定长度的标题名称
' * 参数:所取标题相应调用语句str,显示文字的个数n
' * 返回:以n为显示文字个数的str
' * 作者:醋醋狗
' * 日期:2005/6/5
' *----------------------------------------------------------------------------
Function GetString(str,n)
dim str,n,l,t,ln
ln=n*2
l=len(str)
t=0
for i=1 to l
c=Abs(Asc(Mid(str,i,1)))
if c>255 then
t=t+2
else
t=t+1
end if
if t>=ln then
GetString=left(str,i)&"..."
exit for
else
GetString=str&" "
end if
next
response.write GetString
End Function


禁止从外部提交数据
<%
'server_v1=Cstr(Request.ServerVariables("HTTP_REFERER"))
'server_v2=Cstr(Request.ServerVariables("SERVER_NAME"))
'if mid(server_v1,8,len(server_v2))<>server_v2 then
'response.write "<script>alert('您出错了!!!\n禁止从外部提交数据');history.go(-1);</Script>"
'Response.End
'end if
%>

页面不被缓存语句

Sub ExpirePage
Response.Buffer = True
Response.ExpiresAbsolute = Now() - 1
Response.Expires = 0
Response.CacheControl = "no-cache"
End Sub
在文件的开头调用
<!--#include file="inc/conn.asp"-->
<%call expirepage()%>
就OK了.
再配合
<SCRIPT language=JavaScript>alert('==返回啦==');
javascript:history.go(-1)</SCRIPT>
更爽!!

获得文件扩展名
' *----------------------------------------------------------------------------
' * 函数:GetExtend
' * 描述:获得文件扩展名
' * 参数:文件全名
' * 返回:文件扩展名
' * 作者:
' * 日期:
' *----------------------------------------------------------------------------

function GetExtend(filename)
dim tmp
if filename<>"" then
tmp=mid(filename,instrrev(filename,".")+1,len(filename)-instrrev(filename,"."))
tmp=LCase(tmp)
if instr(1,tmp,"asp")>0 or instr(1,tmp,"php")>0 or instr(1,tmp,"php3")>0 or instr(1,tmp,"aspx")>0 then
getextend="txt"
else
getextend=tmp
end if
else
getextend=""
end if
end function


检测参数是否有SQL危险字符
' *----------------------------------------------------------------------------
' * 函数:CheckIn
' * 描述:检测参数是否有SQL危险字符
' * 参数:str要检测的数据
' * 返回:FALSE:安全 TRUE:不安全
' * 作者:
' * 日期:
' *----------------------------------------------------------------------------
function CheckIn(str)
if instr(1,str,chr(39))>0 or instr(1,str,chr(34))>0 or instr(1,str,chr(59))>0 then
CheckIn=true
else
CheckIn=false
end if
end function

在客户端显示消息框
' *----------------------------------------------------------------------------
' * 函数:alertm
' * 描述:在客户端显示消息框
' * 参数:message:要显示的信息
' * 返回:--
' * 作者:
' * 日期:
' *----------------------------------------------------------------------------
Sub alertm(message)
message = replace(message,"'","'")
Response.Write ("<script>alert('" & message & "')</script>")
End Sub

在客户端返回上一页
' *----------------------------------------------------------------------------
' * 函数:GoBack
' * 描述:在客户端返回上一页
' * 参数:--
' * 返回:--
' * 作者:
' * 日期:
' *----------------------------------------------------------------------------
Sub GoBack()
Response.write ("<script>history.go(-1)</script>")
End Sub

重定向另外的连接
' *----------------------------------------------------------------------------
' * 函数:Go
' * 描述:重定向另外的连接
' * 参数:--
' * 返回:--
' * 作者:
' * 日期:
' *----------------------------------------------------------------------------
Sub Go(url)
Response.write ("<script>location.href('" & url & "')</script>")
End Sub

按指定秒数重定向另外的连接
' *----------------------------------------------------------------------------
' * 函数:GoPage
' * 描述:按指定秒数重定向另外的连接
' * 参数:--
' * 返回:--
' * 作者:
' * 日期:
' *----------------------------------------------------------------------------
sub GoPage(url,s)
s=s*1000
Response.Write "<SCRIPT LANGUAGE=JavaScript>"
Response.Write "window.setTimeout("&chr(34)&"window.navigate('"&url&"')"&chr(34)&","&s&")"
Response.Write "</script>"
end sub

判断数字是否整形

' *----------------------------------------------------------------------------
' * 函数:isInteger
' * 描述:判断数字是否整形
' * 参数:--
' * 返回:--
' * 作者:
' * 日期:
' *----------------------------------------------------------------------------
function isInteger(para)
on error resume next
dim str
dim l,i
if isNUll(para) then
isInteger=false
exit function
end if
str=cstr(para)
if trim(str)="" then
isInteger=false
exit function
end if
l=len(str)
for i=1 to l
if mid(str,i,1)>"9" or mid(str,i,1)<"0" then
isInteger=false
exit function
end if
next
isInteger=true
if err.number<>0 then err.clear
end function

过滤HTML代码
' *----------------------------------------------------------------------------
' * 函数:HTMLEncode
' * 描述:过滤HTML代码
' * 参数:--
' * 返回:--
' * 作者:
' * 日期:
' *----------------------------------------------------------------------------
function HTMLEncode(fString)
if not isnull(fString) then
fString = replace(fString, ">", ">")
fString = replace(fString, "<", "<")

fString = Replace(fString, CHR(32), " ")
fString = Replace(fString, CHR(9), " ")
fString = Replace(fString, CHR(34), """)
fString = Replace(fString, CHR(39), "'")
fString = Replace(fString, CHR(13), "")
fString = Replace(fString, CHR(10) & CHR(10), "</P><P> ")
fString = Replace(fString, CHR(10), "<BR> ")

HTMLEncode = fString
end if
end function

过滤表单字符
' *----------------------------------------------------------------------------
' * 函数:HTMLcode
' * 描述:过滤表单字符
' * 参数:--
' * 返回:--
' * 作者:
' * 日期:
' *----------------------------------------------------------------------------
function HTMLcode(fString)
if not isnull(fString) then
fString = Replace(fString, CHR(13), "")
fString = Replace(fString, CHR(10) & CHR(10), "</P><P>")
fString = Replace(fString, CHR(34), "")
fString = Replace(fString, CHR(10), "<BR>")
HTMLcode = fString
end if
end function

解决过滤

' *----------------------------------------------------------------------------
' * 函数:HTMLREM
' * 描述:解决过滤
' * 参数:--
' * 返回:--
' * 作者:
' * 日期:
' *----------------------------------------------------------------------------
function HTMLREM(fString)
if not isnull(fString) then
fString = Replace(fString, CHR(13), "")
fString = Replace(fString, CHR(10) & CHR(10), "")
fString = Replace(fString, CHR(10), "")
fString=ReplaceSpace(fString)
fString=HTMLEncode(fString)
HTMLREM = fString
end if
end function

替换所有相连空格为单空格
' *----------------------------------------------------------------------------
' * 函数:ReplaceSpace
' * 描述:替换所有相连空格为单空格
' * 参数:--
' * 返回:--
' * 作者:
' * 日期:
' *----------------------------------------------------------------------------
function ReplaceSpace(content)
content=trim(content)
if content="" then
replacespace=""
else
while not instr(1,content," ")=0
content=Replace(content," "," ")
wend
replacespace=content
end if
end function

rem 将字串处理成sql中语句的一部分之搜索条件

function StrToSql_or(content,field)
content=trim(content)
if content="" then
strtosql_or=""
else
' and
strtosql_or=field & " like '%" & replace(content," ","%' or " & field & " like '%") & "%'"
end if
end function

rem 将字串处理成sql中语句的一部分之搜索日期
function StrToSql_Date(searchdate,field)
searchdate=clng(searchdate)
select case searchdate
case 0
StrToSql_Date=""
case 1
StrToSql_Date=field & " between '" & dateadd("ww",-1,date()) & "' and '" & date() & "'"
case 2
StrToSql_Date=field & " between '" & dateadd("m",-1,date()) & "' and '" & date() & "'"
case 3
StrToSql_Date=field & " between '" & dateadd("q",-1,date()) & "' and '" & date() & "'"
case 4
StrToSql_Date=field & " between '" & dateadd("yyyy",-1,date()) & "' and '" & date() & "'"
end select
end function

function StrToSql_Date2(field)
dim date_Previous,date_next
date_previous=dateadd("d",-(Weekday(date(),2)-1),(date() & " 1:00:00"))
date_next=dateadd("d",(7-Weekday(date(),2)),(date() & " 23:59:59"))
StrToSql_Date2=field & " between '" & date_previous & "' and '" & date_next & "'"
end function

rem 字符截断
function Strfix(content,n)
content=trim(content)
if len(content)>n then
Strfix=left(content,n) & "..."
else
Strfix=content
end if
end function

rem 字符串处理-截断(新闻)
function StrNewfix(content)
content=trim(content)
if len(content)>27 then
strnewfix=left(content,27) & "..."
else
strnewfix=content
end if
end function


身份证号码验证函数

Function CheckIDCard(sStr, ByVal dDate, ByVal nSex)
CheckIDCard = "False"
If IsNull(sStr) or sStr = "" Then Exit Function
If Not IsDate(dDate) or dDate = "" Then Exit Function
If Not IsNumeric(nSex) or nSex = "" Then Exit Function

Dim orE, sDate

Set orE= New RegExp
orE.IgnoreCase= True
orE.Global= True

nSex= CInt(nSex Mod 2)
sDate= Year(dDate) & DblNum(Month(dDate)) & DblNum(Day(dDate))

select Case Len(sStr)
Case 8
If DateDiff("yyyy", dDate, Date()) < 19 Then Exit Function
orE.Pattern= "^[\d]{8}$"
If Not orE.Test(sStr) Then Exit Function
If sStr <> sDate Then Exit Function
Case 15
orE.Pattern= "^[\d]{15}$"
If Not orE.Test(sStr) Then Exit Function
If Mid(sStr, 7, 6) <> Right(sDate, 6) Then Exit Function
If CInt(Mid(sStr, 14, 1)) Mod 2 <> nSex Then Exit Function
Case 18
orE.Pattern= "^(:[\d]{18}|[\d]{17}X)$"
If Not orE.Test(sStr) Then Exit Function
If Mid(sStr, 7, 8) <> sDate Then Exit Function
If CInt(Mid(sStr, 17, 1)) Mod 2 <> nSex Then Exit Function

Dim nN, aW, aC, nL

nN = 0
aW = Array(7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2)
aC = Array("1", "0", "X", "9", "8", "7", "6", "5", "4", "3", "2")

For nL = 1 To 17
nN = nN + CInt(Mid(sStr, nL, 1)) * aW(nL - 1)
Next

If UCase(Right(sStr, 1)) <> aC(nN Mod 11) Then Exit Function
Case Else
Exit Function
End select

Set orE= Nothing

CheckIDCard = "True"
End Function

Function DblNum(nNum)
DblNum = nNum
If DblNum <10 Then DblNum = "0" & DblNum
End Function



rem 计算字符长度时,把一个中文字符当作两个字字符,一个英文字符当作一个字符
Function checkstr(str)
num=Len(str)
Set regEx = New RegExp
regEx.Pattern = "[^ -~]"
regEx.Global = True
Set Matches = regEx.Execute(str)
For Each Match in Matches
num=num+1
Next
checkstr=num
End Function


一个URLDeCode的例子

Function URLDecode(enStr)
dim deStr
dim c,i,v
deStr=""
for i=1 to len(enStr)
c=Mid(enStr,i,1)
if c="%" then
v=eval("&h"+Mid(enStr,i+1,2))
if v<128 then
deStr=deStr&chr(v)
i=i+2
else
if isvalidhex(mid(enstr,i,3)) then
if isvalidhex(mid(enstr,i+3,3)) then
v=eval("&h"+Mid(enStr,i+1,2)+Mid(enStr,i+4,2))
deStr=deStr&chr(v)
i=i+5
else
v=eval("&h"+Mid(enStr,i+1,2)+cstr(hex(asc(Mid(enStr,i+3,1)))))
deStr=deStr&chr(v)
i=i+3
end if
else
destr=destr&c
end if
end if
else
if c="+" then
deStr=deStr&" "
else
deStr=deStr&c
end if
end if
next
URLDecode=deStr
end function

function isvalidhex(str)
isvalidhex=true
str=ucase(str)
if len(str)<>3 then isvalidhex=false:exit function
if left(str,1)<>"%" then isvalidhex=false:exit function
c=mid(str,2,1)
if not (((c>="0") and (c<="9")) or ((c>="A") and (c<="Z"))) then isvalidhex=false:exit function
c=mid(str,3,1)
if not (((c>="0") and (c<="9")) or ((c>="A") and (c<="Z"))) then isvalidhex=false:exit function
end function

response.write URLDeCode("%81W")



利用流保存文件

'*****************************************************************
' function
' 作用 :利用流保存文件
' 参数 :from(远程文件地址),tofile(保存文件位置)
'*****************************************************************
Private Function SaveFiles(byref from,byref tofile)
Dim Datas
Datas=GetData(from,0)
Response.Write "保存成功:<font color=red>"&formatnumber(len(Datas)/1024*2,2)&"</font>Kb"
response.Flush
if formatnumber(len(Datas)/1024*2,2)>1 then
ADOS.Type = 1
ADOS.Mode =3
ADOS.Open
ADOS.write Datas
ADOS.SaveToFile server.mappath(tofile),2
ADOS.Close()
else
Response.Write "保存失败:<font color=red>文件大小"&formatnumber(len(imgs)/1024*2,2)&"Kb,小于1K</font>"
response.Flush
end if
end function

利用fso检测文件是否存在

'*****************************************************************
' function(私有)
' 作用 :利用fso检测文件是否存在,存在返回true,不存在返回false
' 参数 :filespes(文件位置)
'*****************************************************************
Private Function IsExists(byref filespec)
If (FSO.FileExists(server.MapPath(filespec))) Then
IsExists = True
Else
IsExists = False
End If
End Function

利用fso检测文件夹是否存在

'*****************************************************************
' function(私有)
' 作用 :利用fso检测文件夹是否存在,存在返回true,不存在返回false
' 参数 :folder(文件夹位置)
'*****************************************************************
Private Function IsFolder(byref Folder)
If FSO.FolderExists(server.MapPath(Folder)) Then
IsFolder = True
Else
IsFolder = False
End If
End Function

利用fso创建文件夹
'*****************************************************************
' function(私有)
' 作用 :利用fso创建文件夹
' 参数 :fldr(文件夹位置)
'*****************************************************************
Private Function createFolder(byref fldr)
Dim f
Set f = FSO.createFolder(Server.MapPath(fldr))
createFolder = f.Path
Set f=nothing
End Function

保存文件,并自动创建多级文件夹
'*****************************************************************
' function(公有)
' 作用 :保存文件,并自动创建多级文件夹
' 参数 :fromurl(远程文件地址),tofiles (保存位置)
'*****************************************************************
Public Function SaveData(byref FromUrl,byref ToFiles)
ToFiles=trim(Replace(ToFiles,"//","/"))
flName=ToFiles
fldr=""
If IsExists(flName)=false then
GetNewsFold=split(flName,"/")
For i=0 to Ubound(GetNewsFold)-1
if fldr="" then
fldr=GetNewsFold(i)
else
fldr=fldr&"\"&GetNewsFold(i)
end if
If IsFolder(fldr)=false then
createFolder fldr
End if
Next
SaveFiles FromUrl,flName
End if
End function


取得远程数据
'*****************************************************************
' function(公有)
' 作用 :取得远程数据
' 参数 :url(远程文件地址),getmode (模式:0为二进制,1为中文编码)
'*****************************************************************
Public Function GetData(byref url,byref GetMode)
'on error resume next
SourceCode = OXML.open ("GET",url,false)
OXML.send()
if OXML.readystate<>4 then exit function
if GetMode=0 then
GetData = OXML.responseBody
else
GetData = BytesToBstr(OXML.responseBody)
end if
if err.number<>0 then err.Clear
End Function

格式化远程图片地址为本地位置
'*****************************************************************
' function(公有)
' 作用 :格式化远程图片地址为本地位置
' 参数 :imgurl(远程图片地址),imgfolder (本地图片目录),fristname(加入的前缀名称)
'*****************************************************************
Public Function FormatImgPath(byref ImgUrl,byref ImgFolder,byref FristName,byref noimg)
strpath=""
ImgUrl=ImgUrl
if instr(ImgUrl,"Nophoto") or lenb(GetData(ImgUrl,0))<=0 then
strpath=noimg
Response.Write "<a href="&strpath&">"&strpath&"</a>" &vbcrlf
else
if Instr(ImgUrl,".asp") then
strpath=FristName&"_"&Mid(ImgUrl, InStrRev(ImgUrl, "=")+1)&".jpg"
else
strpath=FristName&"_"&Mid(ImgUrl, InStrRev(ImgUrl, "/")+1)
end if
strpath = ImgFolder&"/"&strpath
strpath = Replace(strpath,"//","/")
if left(strpath,1)="/" then strpath=right(strpath,len(strpath)-1)
strpath = trim(strpath)
Response.Write "<a href="&strpath&">"&strpath&"</a>" &vbcrlf
savedata ImgUrl,strpath
end if
FormatImgPath = strpath
End function


CInt()
FUNCTION: 将一个表达式转化为数字类型
SYNTAX: CInt(expression)
ARGUMENTS: 任何有效的字符均可
EXAMPLE: <%
f = "234"
response.write cINT(f) + 2
%>
RESULT: 236
转化字符"234"为数字"234",如果字符串为空,则返回0值 CreateObject()
FUNCTION: 建立和返回一个已注册的ACTIVEX组件的实例。
SYNTAX: CreateObject(objName)
ARGUMENTS: objName 是任何一个有效、已注册的ACTIVEX组件的名字.
EXAMPLE: <%
Set con = Server.CreateObject("ADODB.Connection")
%>
RESULT:

CStr()
FUNCTION: 转化一个表达式为字符串.
SYNTAX: CStr(expression)
ARGUMENTS: expression 是任何有效的表达式。
EXAMPLE: <%
s = 3 + 2
response.write "The result is: " & cStr(s)
%>
RESULT: 转化数字“5”为字符“5”。

Date()
FUNCTION: 返回当前系统日期.
SYNTAX: Date()[/B]
ARGUMENTS: None.
EXAMPLE: <%=Date%>
RESULT: 8/4/99

DateAdd()
FUNCTION: 返回一个被改变了的日期。
SYNTAX: DateAdd(timeinterval,number,date)
ARGUMENTS: timeinterval是时间单位(月,日..); number是时间间隔值,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: 返回两个日期之间的差值 。
SYNTAX: DateDiff(timeinterval,date1,date2 [, firstdayofweek [, firstweekofyear>>)
ARGUMENTS: timeinterval 表示相隔时间的类型,如“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: 返回一个月的第几日 .
SYNTAX: Day(date)
ARGUMENTS: date 是任何有效的日期。
EXAMPLE: <%=Day(#8/4/99#)%>
RESULT: 4

FormatCurrency()
FUNCTION: 返回表达式,此表达式已被格式化为货币值
SYNTAX: FormatCurrency(Expression [, Digit [, LeadingDigit [, Paren [, GroupDigit>>>>)
ARGUMENTS: Digit 指示小数点右侧显示位数的数值。默认值为 -1,指示使用的是计算机的区域设置; LeadingDigit 三态常数,指示是否显示小数值小数点前面的零。
EXAMPLE: <%=FormatCurrency(34.3456)%>
RESULT: $34.35

FormatDateTime()
FUNCTION: 返回表达式,此表达式已被格式化为日期或时间
SYNTAX: FormatDateTime(Date, [, NamedFormat>)
ARGUMENTS: NamedFormat 指示所使用的日期/时间格式的数值,如果省略,则使用 vbGeneralDate.
EXAMPLE: <%=FormatDateTime("08/4/99", vbLongDate)%>
RESULT: Wednesday, August 04, 1999

FormatNumber()
FUNCTION: 返回表达式,此表达式已被格式化为数值.
SYNTAX: FormatNumber(Expression [, Digit [, LeadingDigit [, Paren [, GroupDigit>>>>)
ARGUMENTS: Digit 指示小数点右侧显示位数的数值。默认值为 -1,指示使用的是计算机的区域设置。; LeadingDigit i指示小数点右侧显示位数的数值。默认值为 -1,指示使用的是计算机的区域设置。; Paren 指示小数点右侧显示位数的数值。默认值为 -1,指示使用的是计算机的区域设置。; GroupDigit i指示小数点右侧显示位数的数值。默认值为 -1,指示使用的是计算机的区域设置。.
EXAMPLE: <%=FormatNumber(45.324567, 3)%>
RESULT: 45.325

FormatPercent()
FUNCTION: 返回表达式,此表达式已被格式化为尾随有 % 符号的百分比(乘以 100 )。 (%)
SYNTAX: FormatPercent(Expression [, Digit [, LeadingDigit [, Paren [, GroupDigit>>>>)
ARGUMENTS: 同上.
EXAMPLE: <%=FormatPercent(0.45267, 3)%>
RESULT: 45.267%

Hour()
FUNCTION: 以24时返回小时数.
SYNTAX: Hour(time)
ARGUMENTS:
EXAMPLE: <%=Hour(#4:45:34 PM#)%>
RESULT: 16
(Hour has been converted to 24-hour system)

Instr()
FUNCTION: 返回字符或字符串在另一个字符串中第一次出现的位置.
SYNTAX: Instr([start, > strToBeSearched, strSearchFor [, compare>)
ARGUMENTS: Start为搜索的起始值,strToBeSearched接受搜索的字符串 strSearchFor要搜索的字符compare 比较方式(详细见ASP常数)
EXAMPLE: <%
strText = "This is a test!!"
pos = Instr(strText, "a")
response.write pos
%>
RESULT: 9

InstrRev()
FUNCTION: 同上,只是从字符串的最后一个搜索起
SYNTAX: InstrRev([start, > strToBeSearched, strSearchFor [, compare>)
ARGUMENTS: 同上.
EXAMPLE: <%
strText = "This is a test!!"
pos = InstrRev(strText, "s")
response.write pos
%>
RESULT: 13


Int()
FUNCTION: 返回数值类型,不四舍五入。
SYNTAX: Int(number)
ARGUMENTS:
EXAMPLE: <%=INT(32.89)%>
RESULT: 32

IsArray()
FUNCTION: 判断一对象是否为数组,返回布尔值 .
SYNTAX: IsArray(name)
ARGUMENTS:
EXAMPLE: <%
strTest = "Test!"
response.write IsArray(strTest)
%>
RESULT: False

IsDate()
FUNCTION: 判断一对象是否为日期,返回布尔值
SYNTAX: IsDate(expression)
ARGUMENTS: expression 是任意的变量.
EXAMPLE: <%
strTest = "8/4/99"
response.write IsDate(strTest)
%>
RESULT: True

IsEmpty()
FUNCTION: 判断一对象是否初始化,返回布尔值.
SYNTAX: IsEmpty(expression)
ARGUMENTS:
EXAMPLE: <%
Dim i
response.write IsEmpty(i)
%>
RESULT: True

IsNull()
FUNCTION: 判断一对象是否为空,返回布尔值.
SYNTAX: IsNull(expression)
ARGUMENTS:
EXAMPLE: <%
Dim i
response.write IsNull(i)
%>
RESULT: False

IsNumeric()[/B]
FUNCTION: 判断一对象是否为数字,返回布尔值.
SYNTAX: IsNumeric(expression)
ARGUMENTS:
EXAMPLE: <%
i = "345"
response.write IsNumeric(i)
%>
RESULT: True
就算数字加了引号,ASP还是认为它是数字。

IsObject()
FUNCTION: 判断一对象是否为对象,返回布尔值.
SYNTAX: IsObject(expression)
ARGUMENTS:
EXAMPLE: <%
Set con = Server.CreateObject("ADODB.Connection")
response.write IsObject(con)
%>
RESULT: True


LBound()
FUNCTION: 返回指定数组维的最小可用下标.
SYNTAX: Lbound(arrayname [, dimension>)
ARGUMENTS: dimension 指明要返回哪一维下界的整数。使用 1 表示第一维,2 表示第二维,以此类 推。如果省略 dimension 参数,默认值为 1.
EXAMPLE: <%
i = Array("Monday","Tuesday","Wednesday")
response.write LBound(i)
%>
RESULT: 0

LCase()
FUNCTION: 返回字符串的小写形式
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个字符以前的字符(含第length个字符).
SYNTAX: Left(string, length)
ARGUMENTS:
EXAMPLE: <%
strTest = "This is a test!"
response.write Left(strTest, 3)
%>
RESULT: Thi

Len()
FUNCTION: 返回字符串的长度.
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: 返回特定长度的字符串(从start开始,长度为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: 返回时间的分钟。
SYNTAX: Minute(time)
ARGUMENTS:
EXAMPLE: <%=Minute(#12:45:32 PM#)%>
RESULT: 45

Month()
FUNCTION: 返回一数值, 表示月份 
SYNTAX: Month(time)
ARGUMENTS: time是日期变量 
EXAMPLE: <%=Month(#08/04/99#)%>
RESULT: 8

MonthName()
FUNCTION: 返回月份的字符串(名称).
SYNTAX: Monthname(date [,abb])
ARGUMENTS: date是日期变量,abb=true时 则月份的缩写,
EXAMPLE: <%=MonthName(Month(#08/04/99#))%>
RESULT: August

Now()
FUNCTION: 返回系统的当前时间和日期。
SYNTAX: Now()[/B]
ARGUMENTS: None
EXAMPLE: <%=Now%>
RESULT: 8/4/99 9:30:16 AM

Replace()
FUNCTION: 在字符串中查找,替代指定的字符串.
SYNTAX: replace(strtobesearched,strsearchfor,strreplacewith [,start[,count[,compare]]]) 
ARGUMENTS: strtobesearched是字符串; strsearchfor是被查找的子字符串;strreplacewith 是用来替代的子字符串.start,count,compare 是任意选项
EXAMPLE: <%
strTest = "This is an apple!"
response.write Replace(strTest, "apple", "orange")
%>
RESULT: This is an orange!

Right()
FUNCTION: 返回字符串右边第length个字符以前的字符(含第length个字符).
SYNTAX: Right(string, length)
ARGUMENTS: .
EXAMPLE: <%
strTest = "This is an test!"
response.write Right(strTest, 3)
%>
RESULT: st!

Rnd()
FUNCTION: 产生一个随机数.
SYNTAX: Rnd [ (number) >
ARGUMENTS:
EXAMPLE: <%
Randomize()[/B]
response.write RND()[/B]
%>
RESULT: 任何一个在0 到 1 之间的数

Round()
FUNCTION: 返回按指定位数进行四舍五入的数值.
SYNTAX: Round(expression [, numRight>)
ARGUMENTS: numRight数字表明小数点右边有多少位进行四舍五入。如果省略,则 Round 函数返回整数.
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: 返回系统时间.
SYNTAX: Time()[/B]
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: 返回指定数组维数的最大可用下标.
SYNTAX: Ubound(arrayname [, dimension>)
ARGUMENTS: dimension (optional) 指定返回哪一维上界的整数。1 表示第一维,2 表示第二维,以此类推。如果省略 dimension 参数,则默认值为 1.
EXAMPLE: <%
i = Array("Monday","Tuesday","Wednesday")
response.write UBound(i)
%>
RESULT: 2

UCase()
FUNCTION: 返回字符串的大写形式.
SYNTAX: UCase(string)
ARGUMENTS:
EXAMPLE: <%
strTest = "This is a test!!"
response.write UCase(strTest)
%>
RESULT: THIS IS A TEST!!

VarType()
FUNCTION: 返回指示变量子类型的值
SYNTAX: VarType(varName)
ARGUMENTS:
EXAMPLE: <%
i = 3
response.write varType(i)
%>
RESULT: 2(数字)详见"asp常数"

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 值,指明是否缩写表示星期各天的名称。如果省略, 默认值为 False,即不缩写星期各天的名称.firstdayofweek指明星期第一天的数值
EXAMPLE: <%
d = #8/4/99#
response.write WeekdayName(Weekday(d))
%>
RESULT: Wednesday

Year()
FUNCTION: 返回当前的年份.
SYNTAX: Year(date)
ARGUMENTS:
EXAMPLE: <%=Year(#8/4/99#)%>
RESULT: 1999

函数Mod()
FUNCTION:取余数.
EXAMPLE:3 Mod 2 
RESULT:1

原文:http://hi.baidu.com/flyhart/blog/item/062cd3ce72c8ba0393457e62.html

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics