当前位置: 首页 > 图文教程 > 网络编程 > ASP > ASP中常用的函数和详细说明

ASP
asp实现取得数组中的最大值的代码
asp 将日期格式化为需要的格式
asp 下产生任意位数随机密码的代码
asp下返回以千分位显示数字格式化的数值
asp重定向页面的方法总结
asp下去除数组中重复的项的方法
asp下实现 重新排序数字数组的代码
asp 验证输入网址是否有效并可以访问 与正则验证输入网址
asp验证Ip格式的函数
asp实现生成由数字,大写字母,小写字母指定位数的随机数
asp 格式化sql中的like字符串
asp 实现显示所有的服务器变量值的函数
asp 取得用户真实IP,对代理地址仍然有效的函数
asp 通用数据库连接过程函数
asp 字符串截取函数
asp下实现格式化文件大小以MB显示的函数
asp 下用正则表达式检测邮箱格式的函数
asp 实现检测字符串是否为纯字母和数字组合的函数
asp代码实现检测组件是否安装的函数
asp通过JMAIL实现通用发送函数

ASP中常用的函数和详细说明


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-09-13   浏览: 108 ::
收藏到网摘: n/a

各位都把ASP用的函数和详细说明贴出来,供大家学习.
我知道的如下:
1.函数array() 
功能:创建一个数组变量 
格式:array(list) 
参数:list 为数组变量中的每个数值列,中间用逗号间隔 
例子: 
<% i = array ("1","2","3") %> 
结果: i 被赋予为数组 
2.函数Cint() 
功能:将一表达式/其它类型的变量转换成整数类型(int) 
格式:Cint(expression) 
参数:expression 是任何有效的表达式/其它类型的变量 
例子: 
<% 
f = "234" 
response.write cINT(f) + 2 
%> 
结果: 236 
函数Cint()将字符"234"转换 成整数234.如果表达式为空, 或者无效时,返回值为0; 
3.函数:Creatobject() 
功能:创建及返回一个ActiveX对象. 
格式:Creatobject(obname) 
参数bname 是对象的名称 
例子: 
<% 
Set con = Server.CreateObject("ADODB.Connection") 
%> 
结果: 
4.函数Cstr() 
功能:将一表达式/其它类型的变量转换成字符类型(string) 
格式:Cstr(expression) 
参数:expression是任何有效的表达式/其它类型的变量 
例子: 
<% 
s = 3 + 2 
response.write "The result is:" & cStr(s) 
%> 
结果:函数Cstr()将整数 5 转换 成字符"5". 
5.函数Date() 
功能:返回当前系统(server端)的日期 
格式: Date() 
参数:无 
例子<% date () %> 
结果:05/10/00 
6.函数Dateadd() 
功能:计算某个指定的时间和 
格式: dateadd(timeinterval,number,date) 
参数:timeinterval是时间单位(月,日..); number是时间间隔值,date是时间始点. 
例子: 
<% 
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 
%> 
结果: 
11/4/99 
3:34:45 PM 
其中 
"m" = "month"; 
"d" = "day"; 
如果是currentDate 格式,则, 
"h" = "hour"; 
"s" = "second"; 
7.函数Datediff() 
功能:计算某量个指定的时间差 
格式: datediff(timeinterval,date1,date2[,firstdayofweek[,firstdayofyear]]) 
参数: timeinterval 是时间单位; date1,date2是有效的日期表达式,firstdayofweek,firstdayofyear 是任意选项. 
例子: 
<% 
fromDate = #8/4/99# 
toDate = #1/1/2000# 
response.write "There are " & _ 
DateDiff("d",fromDate,toDate) & _ 
" days to millenium from 8/4/99." 
%> 
结果:There are 150 days to millenium from 8/4/99. 
8.函数day() 
功能:返回一个整数值,对应于某月的某日 
格式: day(date) 
参数: date是一个有效的日期表达式; 
例子<% =date(#8/4/99#) %> 
结果:4 
9.函数formatcurrency() 
功能:转换成货币格式 
格式: formatcurrency(expression [,digit[,leadingdigit[,paren[,groupdigit]]]]) 
参数: expression 是有效的数字表达式;digit表示小数点后的位数;leadingdigit,paren,groupdigit是任意选项. 
例子<%=formatCurrency(34.3456)%> 
结果34.35 
10.函数formatdatetime() 
功能:格式化日期表达式/变量 
格式: formatdatetime(date[,nameformat]) 
参数: date为有效的日期表达式/变量;nameformat是指定的日期格式常量名称. 
例子<% =formatdatetime("08/04/99",vblongdate) %> 
结果:Wednesday,August 04,1999 
说明: 
-------------------------------------------------------------------<script language=vbs>
for i=0 to 4
alert(" formatdatetime(now,"&i&") 的时候是:"&formatdatetime(now,i))
next
</script>
-------------
描述
返回表达式,此表达式已被格式化为日期或时间。 
语法
formatDateTime(Date[, Namedformat])
formatDateTime 函数的语法有以下参数:
参数 描述 
Date 必选项。要被格式化的日期表达式。 
Namedformat 可选项。指示所使用的日期/时间格式的数值,如果省略,则使用 vbGeneralDate。 

设置
Namedformat 参数可以有以下值:
常数 值 描述 
vbGeneralDate 0 显示日期和/或时间。如果有日期部分,则将该部分显示为短日期格式。如果有时间部分,则将该部分显示为长时间格式。如果都存在,则显示所有部分。 
vbLongDate 1 使用计算机区域设置中指定的长日期格式显示日期。 
vbShortDate 2 使用计算机区域设置中指定的短日期格式显示日期。 
vbLongTime 3 使用计算机区域设置中指定的时间格式显示时间。 
vbShortTime 4 使用 24 小时格式 (hh:mm) 显示时间。 
说明
下面例子利用 formatDateTime 函数把表达式格式化为长日期型并且把它赋给 MyDateTime: 
Function GetCurrentDate 
"formatDateTime 把日期型格式化为长日期型。
GetCurrentDate = formatDateTime(Date, 1) 
End Function
--------------------------------------------------------------------------------
<script language=vbs>
for i=0 to 4
alert(" formatdatetime(now,"&i&") 的时候是:"&formatdatetime(now,i))
next
</script>
[Ctrl+A 全部选择 提示:你可先修改部分代码,再按运行]  
11.函数Isnumeric() 
功能:返回一个布尔值,判断变量是否为数字变量,或者是可以转换成数字的其它变量. 
格式:isnumeric(expression) 
参数:expression 是任意的变量. 
例子: 
<% 
i="234" 
response.write isnumeric(i) 
%> 
结果: true. 
12.函数Isobject() 
功能:返回一个布尔值,判断变量是否为对象的变量, 
格式: isobject(expression) 
参数: expression 是任意的变量. 
例子: 
<% 
set con =server.creatobject("adodb.connection") 
response.write isobject(con) 
%> 
结果: true 
13.函数:Lbound() 
功能:返回一个数组的下界. 
格式:Lbound(arrayname[,dimension]) 
参数:arrayname 是数组变量,dimension 是任意项 
例子: 
<% 
i = array("1","2","3") 
response.write lbound(i) 
%> 
结果:0
14.函数Lcase() 
功能:将一字符类型变量的字符全部变换小写字符. 
格式:Lcase(string) 
参数:string是字符串变量 
例子: 
<% 
str="THIS is Lcase!" 
response.write Lcase(str) 
%> 
结果:this is lcase! 
15.函数left() 
功能:截取一个字符串的前部分; 
格式:left(string,length) 
参数:string字符串,length截取的长度. 
例子: <% =left("this is a test!",6) %> 
结果:this i 
16.函数len() 
功能:返回字符串长度或者变量的字节长度 
格式:len(string *varname) 
参数:string字符串;varname任意的变量名称 
例子: 
<% 
strtest="this is a test!" 
response.write len(strtest) 
%> 
结果:15 
17.函数ltrim() 
功能:去掉字符串前的空格. 
格式:ltrim(string) 
参数:string 字符串. 
例子: <% =ltrim (" this is a test!") 
结果:this is a test! 
18.函数Mid() 
功能:从字符串中截取字符串. 
格式:mid(string,start [,length]) 
参数:string字符串,start截取的起点,length要截取的长度. 
例子: 
<% 
strtest="this is a test, Today is Monday!" 
response.write mid(strtest,17,5) 
%> 
结果:Today 
19.函数minute() 
功能:返回一数值, 表示分钟 
格式:minute(time) 
参数: time是时间变量 
例子lt;% =minute(#12:23:34#) %> 
结果:23 

20.函数month() 
功能:返回一数值, 表示月份 
格式:month(time) 
参数:time是日期变量 
例子<% =month(#08/09/99) %> 
结果:9 
21.函数monthname() 
功能:返回月份的字符串(名称). 
格式:Monthname(date [,abb]) 
参数: date是日期变量,abb=true时 则月份的缩写, 
例子: 
<% =monthname(#4/5/99#) %> 
结果:April 
22.函数Now() 
功能:返回系统的当前时间和日期. 
格式:now() 
参数:无 
例子: 
<% =now() %> 
结果: 05/10/00 8:45:32 pm 
23.函数:replace() 
功能:在字符串中查找,替代指定的字符串. 
格式:replace(strtobesearched,strsearchfor,strreplacewith [,start[,count[,compare]]]) 
参数:strtobesearched是字符串; strsearchfor是被查找的子字符串;strreplacewith 是用来替代的子字符串.start,count,compare 是任意选项. 
例子: 
<% 
strtest="this is an apple." 
response.write replace(strtest,"apple","orange") 
%> 
结果:this is an orange. 
24.函数right() 
功能:截取一个字符串的后部分 
格式:right(string,length) 
参数:string字符串,length截取的长度. 
例子: 
<% 
strtest="this is a test!" 
response.write right(strtest,3) 
%> 
结果:st! 
25.函数rnd() 
功能:返回一个随机数值 
格式:rnd[(number)] 
参数:number是任意数值. 
例子: 
<% 
randomize() 
response.write rnd() 
%> 
结果:0/1数值之一,无randomize(), 则不能产生随机数. 
26.函数round() 
功能:完整数值 
格式:round(expression[,numright]) 
参数:expression数字表达式;numright任意选项. 
例子: 
<% 
i=12.33654 
response.write round(i) 
%> 
结果: 12 
27.函数rtrim() 
功能:去掉字符串后的空格. 
格式:rtrim(string) 
参数:string 是字符串 
例子: 
<% 
response.write rtrim("this is a test! ") 
%> 
结果:this is a test! 
28.函数second() 
功能:返回一个整数值. 
格式:second(time) 
参数:time是一个有效的时间表达式; 
例子lt;% =second(# 12:28:30#) %> 
结果:30 
29.函数strReverse() 
功能:返回与原字符串排列逆向的字符串. 
格式:strreverse(string) 
参数:string是字符串 
例子<% =strreverse("this is a test!") 
结果:!tset a si siht 
30.函数time() 
功能:返回当前系统的时间值. 
格式:time() 
参数:无 
结果:9:58:28 Am 
31.函数trim() 
功能:删去字符串前,后的空格. 
格式:trim(string) 
参数:string 字符串. 
例子: 
<% 
strtest=" this is a test! " 
response.write trim(strtest) 
%> 
结果:this is a test! 
32.函数UBound() 
功能:返回一个数组的上界. 
格式:Ubound(expression [,dimension]) 
参数:expression 是数组表达式/数组变量,dimension 是任意项 
例子: 
<% 
i = array("1","2","3") 
response.write ubound(i) 
%> 
结果: 2 
33.函数:UCase() 
功能:将一字符类型变量的字符全部变换成大写字符. 
格式:Ucase(string) 
参数:string是字符串变量 
例子: 
<% 
str="THIS is Lcase!" 
response.write Lcase(str) 
%> 
结果:THIS IS LCASE! 
34.函数Vartype() 
功能:返回变量的常量代码(整数) 
格式:Vartype(varname) 
参数:varname是任何类型的变量名称. 
例子: 
<% 
i=5 
response.write vartype(i) 
%> 
结果:2 (2表示整数,须要参考ASP常量代码.) 
35.函数Weekday() 
功能:返回一个整数,对应一周中的第几天. 
格式:Weekday(date [,firstofweek]) 
参数: date为日期变量,firstofweek为任选项. 
例子: 
<% 
d= # 5/9/00 # 
response.write weekday(d) %> 
结果:3(3 表示是星期二) 
36.函数weekdayname() 
功能:返回字符串,对应星期几. 
格式:weekdayname(weekday[,abb[,firstdayofweek]]) 
参数:weekday为日期变量,abb,firstdayofweek为任选项. 
例子: 
<% 
d = #8/4/99# 
response.write weekdayname(d) 
%> 
结果: Wednesday 
37.函数year() 
功能:返回日期表达式所在的年份. 
格式:year(date) 
参数: date是有效的日期表达式 
例子: 
<% =year(#8/9/99#) %> 
结果:1999 
38.函数Mod()功能:取余数.
例子:3 Mod 2 
结果:1
我先介绍一下Split函数的用法:
 返回值数组 = Split("字符串","分割符")
39.split函数的应用
作者:李春光 转贴自:本站原创 点击数:113 文章录入:
split 是一个分隔字符串的函数,它的作用是把用特定分隔符隔开的字符串转化为一个数组,这在编程中用的比较多,如上传多张图片,在数库中仅能用一个字段存储的情况下,split就起作用了,下面是一个具体的例子,和数组结合使用.
<%
dim str1
str1="icerain|fengling|windbell|"
aryReturn=split(str1,"|")
response.write "返回的是否为数组"&IsArray(aryReturn)
response.write "<br>"
for i=LBound(aryReturn) TO UBound(aryReturn)
response.write aryReturn(i)
response.write "<br>"
next
response.end
%>
Rnd() 
 
函数产生一个随机数. 
 
表达式 Rnd [ (number) ] 
 
实例: <% 
 
Randomize() 
response.write RND() 
 
%> 
 
返回结果: 任何一个在0 到 1 之间的数