ASP常用的库函数大全.docx

上传人:b****8 文档编号:9134830 上传时间:2023-02-03 格式:DOCX 页数:18 大小:20.31KB
下载 相关 举报
ASP常用的库函数大全.docx_第1页
第1页 / 共18页
ASP常用的库函数大全.docx_第2页
第2页 / 共18页
ASP常用的库函数大全.docx_第3页
第3页 / 共18页
ASP常用的库函数大全.docx_第4页
第4页 / 共18页
ASP常用的库函数大全.docx_第5页
第5页 / 共18页
点击查看更多>>
下载资源
资源描述

ASP常用的库函数大全.docx

《ASP常用的库函数大全.docx》由会员分享,可在线阅读,更多相关《ASP常用的库函数大全.docx(18页珍藏版)》请在冰豆网上搜索。

ASP常用的库函数大全.docx

ASP常用的库函数大全

<%

'判断文件名是否合法

FunctionisFilename(aFilename)

DimsErrorStr,iNameLength,i

isFilename=TRUE

sErrorStr=Array("/","\",":

","*","?

","""","<",">","|")

iNameLength=Len(aFilename)

IfiNameLength<1OriNameLength=nullThen

  isFilename=FALSE

Else

  Fori=0To8

   Ifinstr(aFilename,sErrorStr(i))Then

    isFilename=FALSE    

   EndIf

  Next

EndIf

EndFunction

'去掉字符串头尾的连续的回车和空格

functiontrimVBcrlf(str)

trimVBcrlf=rtrimVBcrlf(ltrimVBcrlf(str))

endfunction

'去掉字符串开头的连续的回车和空格

functionltrimVBcrlf(str)

dimpos,isBlankChar

pos=1

isBlankChar=true

whileisBlankChar

  ifmid(str,pos,1)=""then

   pos=pos+1

  elseifmid(str,pos,2)=VBcrlfthen

   pos=pos+2

  else

   isBlankChar=false

  endif

wend

ltrimVBcrlf=right(str,len(str)-pos+1)

endfunction

'去掉字符串末尾的连续的回车和空格

functionrtrimVBcrlf(str)

dimpos,isBlankChar

pos=len(str)

isBlankChar=true

whileisBlankCharandpos>=2

  ifmid(str,pos,1)=""then

   pos=pos-1

  elseifmid(str,pos-1,2)=VBcrlfthen

   pos=pos-2

  else

   isBlankChar=false

  endif

wend

rtrimVBcrlf=rtrim(left(str,pos))

endfunction

'判断Email是否有效,返回1表示正确

FunctionisEmail(aEmail)

DimiLocat,v,iLength,i,checkletter

Ifinstr(aEmail,"@")=0Orinstr(aEmail,".")=0Then

  isEmail=0

  EXITFUNCTION

EndIf

iLocat=instr(aEmail,"@")

Ifinstr(iLocat,aEmail,".")=0Orinstr(iLocat+1,aEmail,"@")>0Then

  isEmail=0

  EXITFUNCTION

EndIf

Ifleft(aEmail,1)="."Orright(aEmail,1)="."Orleft(aEmail,1)="@"Orright(aEmail,1)="@"Then

  isEmail=0

  EXITFUNCTION

EndIf

v="1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_-.@"

iLength=len(aEmail)

Fori=1ToiLength

  checkletter=mid(aEmail,i,1)

  Ifinstr(v,checkletter)=0Then

   isEmail=0

   EXITFUNCTION

  EndIf

Next

isEmail=1

EndFunction

'测试用:

显示服务器信息

SubshowServer

Dimname

Response.write""

foreachnameinrequest.servervariables

  Response.write""

  Response.write""&name&""

  Response.write""&request.servervariables(name)&"
"

  Response.write""

next

Response.write""

EndSub

'测试用:

显示Rs结果集以及字段名称

SubshowRs(rs)

DimstrTable,whatever

Response.write"

"

foreachwhateverinrs.fields

  response.write"

"

next

strTable="

"&whatever.name&"
"&rs.GetString(,,"","
","")&"
"

Response.Write(strTable)

EndSub

'用HTML格式显示文本

Functiontxt2Html(str)

ifisnull(str)then

  txt2Html=""

  exitFunction

endif

str=Replace(str,chr(34),""")

str=Replace(str,"<","<")

str=Replace(str,">",">")

str=Replace(str,chr(13)+chr(10),"
")

str=Replace(str,chr(9),"    ")

str=Replace(str,"","")

txt2Html=str

EndFunction

'测试用:

显示调试错误信息

SubshowError

DimsErrMsg

sErrMsg=Err.Source&""&Err.Description

Response.write"

"&sErrMsg&"
"

Err.clear

EndSub

'显示文字计数器

SubshowCounter

Dimfs,outfile,filename,count

filename=server.mappath("count.txt")

Setfs=CreateObject("Scripting.FileSystemObject")

Iffs.fileExists(filename)Then

Setoutfile=fs.openTextFile(filename,1)

count=outfile.readline

count=count+1

Response.write"

浏览人次:

"&count&"

"

outfile.close

Setoutfile=fs.CreateTextFile(filename)

outfile.writeline(count)

Else

Setoutfile=fs.openTextFile(filename,8,TRUE)

count=0

outfile.writeline(count)

ENDIF

outfile.close

setfs=nothing

EndSub

%>

Array()

 FUNCTION:

返回一个数组

 SYNTAX:

Array(list)

 ARGUMENTS:

字符,数字均可

 EXAMPLE:

<%

DimmyArray()

Fori=1to7

 RedimPreservemyArray(i)

 myArray(i)=WeekdayName(i)

Next

%>

 RESULT:

建立了一个包含7个元素的数组myArray

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

 

CInt()

 FUNCTION:

将一个表达式转化为数字类型

 SYNTAX:

CInt(expression)

 ARGUMENTS:

任何有效的字符均可

 EXAMPLE:

<%

f="234"

response.writecINT(f)+2

%>

 RESULT:

236

转化字符"234"为数字"234",如果字符串为空,则返回0值 

 

CreateObject()

 FUNCTION:

建立和返回一个已注册的ACTIVEX组件的实例。

 SYNTAX:

CreateObject(objName)

 ARGUMENTS:

objName是任何一个有效、已注册的ACTIVEX组件的名字.

 EXAMPLE:

<%

Setcon=Server.CreateObject("ADODB.Connection")

%>

 RESULT:

 

 

CStr()

 FUNCTION:

转化一个表达式为字符串.

 SYNTAX:

CStr(expression)

 ARGUMENTS:

expression是任何有效的表达式。

 EXAMPLE:

<%

s=3+2

response.write"Theresultis:

"&cStr(s)

%>

 RESULT:

转化数字“5”为字符“5”。

 

Date()

 FUNCTION:

返回当前系统日期.

 SYNTAX:

Date()

 ARGUMENTS:

None.

 EXAMPLE:

<%=Date%>

 RESULT:

8/4/99

 

DateAdd()

 FUNCTION:

返回一个被改变了的日期。

 SYNTAX:

DateAdd(timeinterval,number,date)

 ARGUMENTS:

timeintervalisthetimeintervaltoadd;numberisamountof

timeintervalstoadd;anddateisthestartingdate.

 EXAMPLE:

<%

currentDate=#8/4/99#

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

response.writenewDate

%>

<%

currentDate=#12:

34:

45PM#

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

response.writenewDate

%>

 RESULT:

11/4/99

3:

34:

45PM

"m"="month";

"d"="day";

IfcurrentDateisintimeformatthen,

"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"Thereare"&_

 DateDiff("d",fromDate,toDate)&_

 "daystomilleniumfrom8/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,August04,1999

 

FormatNumber()

 FUNCTION:

返回表达式,此表达式已被格式化为数值.

 SYNTAX:

FormatNumber(Expression[,Digit][,LeadingDigit][,Paren][,

GroupDigit]]]])

 ARGUMENTS:

 Digit指示小数点右侧显示位数的数值。

默认值为-1,指示使用的是

计算机的区域设置。

;LeadingDigiti指示小数点右侧显示位数的数值。

默认值为-

1,指示使用的是计算机的区域设置。

;Paren指示小数点右侧显示位数的数值。

默认

值为-1,指示使用的是计算机的区域设置。

;GroupDigiti指示小数点右侧显示位数

的数值。

默认值为-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:

34PM#)%>

 RESULT:

16

(Hourhasbeenconvertedto24-hoursystem)

 

Instr()

 FUNCTION:

返回字符或字符串在另一个字符串中第一次出现的位置.

 SYNTAX:

Instr([start,]strToBeSearched,strSearchFor[,compare])

 ARGUMENTS:

Start为搜索的起始值,strToBeSearched接受搜索的字符串 

strSearchFor要搜索的字符.compare比较方式(详细见ASP常数)

 EXAMPLE:

<%

strText="Thisisatest!

!

"

pos=Instr(strText,"a")

response.writepos

%>

 RESULT:

9

 

InstrRev()

 FUNCTION:

同上,只是从字符串的最后一个搜索起

 SYNTAX:

InstrRev([start,]strToBeSearched,strSearchFor[,compare])

 ARGUMENTS:

同上.

 EXAMPLE:

<%

strText="Thisisatest!

!

"

pos=InstrRev(strText,"s")

response.writepos

%>

 RESULT:

13

 

Int()

 FUNCTION:

返回数值类型,不四舍五入,注意取值是不大于它的整数。

 SYNTAX:

Int(number)

 ARGUMENTS:

 

 EXAMPLE:

<%=INT(32.89)%> <%=int(-3.33)%>

 RESULT:

32  -4

 

IsArray()

 FUNCTION:

判断一对象是否为数组,返回布尔值 .

 SYNTAX:

IsArray(name)

 ARGUMENTS:

 

 EXAMPLE:

<%

strTest="Test!

"

response.writeIsArray(strTest)

%>

 RESULT:

False

 

IsDate()

 FUNCTION:

判断一对象是否为日期,返回布尔值

 SYNTAX:

IsDate(expression)

 ARGUMENTS:

expressionisanyvalidexpression.

 EXAMPLE:

<%

strTest="8/4/99"

response.writeIsDate(strTest)

%>

 RESULT:

True

 

IsEmpty()

 FUNCTION:

判断一对象是否初始化,返回布尔值.

 SYNTAX:

IsEmpty(expression)

 ARGUMENTS:

 

 EXAMPLE:

<%

Dimi

response.writeIsEmpty(i)

%>

 RESULT:

True

 

IsNull()

 FUNCTION:

判断一对象是否为空,返回布尔值.

 SYNTAX:

IsNull(expression)

 ARGUMENTS:

 

 EXAMPLE:

<%

Dimi

response.writeIsNull(i)

%>

 RESULT:

False

 

IsNumeric()

 FUNCTION:

判断一对象是否为数字,返回布尔值.

 SYNTAX:

IsNumeric(expression)

 ARGUMENTS:

 

 EXAMPLE:

<%

i="345"

response.writeIsNumeric(i)

%>

 RESULT:

True

就算数字加了引号,ASP还是认为它是数字。

 

IsObject()

 FUNCTION:

判断一对象是否为对象,返回布尔值.

 SYNTAX:

IsObject(expression)

 ARGUMENTS:

 

 EXAMPLE:

<%

Setcon=Server.CreateObject("ADODB.Connection")

response.writeIsObject(con)

%>

 RESULT:

True

 

LBound()

 FUNCTION:

返回指定数组维的最小可用下标.

 SYNTAX:

Lbound(arrayname[,dimension])

 ARGUMENTS:

;dimension指明要返回哪一维下界的整数。

使用1表示第一维,2

表示第二维,以此类推。

如果省略dimension参数,默认值为1.

 EXAMPLE:

<%

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

response.writeLBound(i)

%>

 RESULT:

0

 

LCase()

 FUNCTION:

 返回字符串的小写形式

 SYNTAX:

Lcase(string)

 ARGUMENTS:

stringisanyvalidstringexpression.

 EXAMPLE:

<%

strTest="Thisisatest!

"

response.writeLCase(strTest)

%>

 RESULT:

thisisatest!

 

Left()

 FUNCTION:

返回字符串左边第length个字符以前的字符(含第length个字符).

 SYNTAX:

Left(string,length)

 ARGUMENTS:

 

 EXAMPLE:

<%

strTest="Thisisatest!

"

response.writeLeft(strTest,3)

%>

 RESULT:

Thi

 

Len()

 FUNCTION:

返回字符串的长度.

 SYNTAX:

Len(string|varName)

 ARGUMENTS:

 

 EXAMPLE:

<%

strTest="Thisisatest!

"

response.writeLen(strTest)

%>

 RESULT:

15

 

LTrim()

 FUNCTION:

去掉字符串左边的空格.

 SYNTAX:

LTrim(string)

 ARGUMENTS:

 

 EXAMPLE:

<%

strTest="Thisisatest!

"

response.writeLTrim(strTest)

%>

 RESULT:

Thisisatest!

 

Mid()

 FUNCTION:

返回特定长度的字符串(从start开始,长度为length).

 SYNTAX:

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > PPT模板 > 动态背景

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1