• Asp 函数大全!

  • 阿梁 于 2012/4/8 17:12:34 2817 次浏览 5 参与讨论
 

ASP函数与VBSCRIPT类似,以下举一些常用的函数 
 
Array() 
 
函数返回一个数组 
 
表达式 Array(list) 
 
允许数据类型: 字符,数字均可 
 
实例: <% 
 
Dim myArray() 
 
For i = 1 to 7 
 
Redim Preserve myArray(i) 
 
myArray(i) = WeekdayName(i) 
 
Next 
 
%> 
 
返回结果: 建立了一个包含7个元素的数组myArray 
 
myArray("Sunday","Monday", ... ... "Saturday") 
 
 
CInt() 
 
函数将一个表达式转化为数字类型 
 
表达式 CInt(expression) 
 
允许数据类型: 任何有效的字符均可 
 
实例: <% 
 
f = "234" 
 
response.write cINT(f) + 2 
 
%> 
 
返回结果: 236 
 
转化字符"234"为数字"234",如果字符串为空,则返回0值 
 
 
CreateObject() 
 
函数建立和返回一个已注册的ACTIVEX组件的实例。 
 
表达式 CreateObject(objName) 
 
允许数据类型: objName 是任何一个有效、已注册的ACTIVEX组件的名字. 
 
实例: <% 
 
Set con = Server.CreateObject("ADODB.Connection") 
 
%> 
 
 
CStr() 
 
函数转化一个表达式为字符串. 
 
表达式 CStr(expression) 
 
允许数据类型: expression 是任何有效的表达式。 
 
实例: <% 
 
s = 3 + 2 
 
response.write "The 返回结果 is: " & cStr(s) 
 
%> 
 
返回结果: 转化数字“5”为字符“5”。 
 
 
Date() 
 
函数返回当前系统日期. 
 
表达式 Date() 
 
允许数据类型: None. 
 
实例: <%=Date%> 
 
返回结果: 9/9/00 
 
 
DateAdd() 
 
函数返回一个被改变了的日期。 
 
表达式 DateAdd(timeinterval,number,date) 
 
允许数据类型: 
timeinterval is the time interval to add; 
number is amount of time intervals to add; 
and date is the starting date. 
 
实例: <% 
 
currentDate = #9/9/00# 
 
newDate = DateAdd("m",3,currentDate) 
 
response.write newDate 
 
%> 
 
 
<% 
 
currentDate = #12:34:45 PM# 
 
newDate = DateAdd("h",3,currentDate) 
 
response.write newDate 
 
%> 
 
返回结果: 9/9/00 
 
3:34:45 PM 
 
"m" = "month"; 
 
"d" = "day"; 
 
If currentDate is in time format then, 
 
"h" = "hour"; 
 
"s" = "second"; 
 
 
DateDiff() 
 
函数返回两个日期之间的差值 。 
 
表达式 DateDiff(timeinterval,date1,date2 [, firstdayofweek [, firstweekofyear]]) 
 
允许数据类型: timeinterval 表示相隔时间的类型,如“M“表示“月”。 
 
实例: <% 
 
fromDate = #9/9/00# 
 
toDate = #1/1/2000# 
 
response.write "There are " & _ 
 
DateDiff("d",fromDate,toDate) & _ 
 
" days to millenium from 9/9/00." 
 
%> 
 
返回结果: 从9/9/00 到2000年还有 150 天. 
 
 
Day() 
 
函数返回一个月的第几日 . 
 
表达式 Day(date) 
 
允许数据类型: date 是任何有效的日期。 
 
实例: <%=Day(#9/9/00#)%> 
 
返回结果: 4 
 
 
FormatCurrency() 
 
函数返回表达式,此表达式已被格式化为货币值 
 
表达式 FormatCurrency(Expression [, Digit [, LeadingDigit [, Paren [, GroupDigit]]]]) 
 
允许数据类型: Digit 指示小数点右侧显示位数的数值。默认值为 -1,指示使用的是计算机的区域设置; LeadingDigit 三态常数,指示是否显示小数值小数点前面的零。

ASP函数与VBSCRIPT类似,以下举一些常用的函数 
 
Array() 
 
函数返回一个数组 
 
表达式 Array(list) 
 
允许数据类型: 字符,数字均可 
 
实例: <% 
 
Dim myArray() 
 
For i = 1 to 7 
 
Redim Preserve myArray(i) 
 
myArray(i) = WeekdayName(i) 
 
Next 
 
%> 
 
返回结果: 建立了一个包含7个元素的数组myArray 
 
myArray("Sunday","Monday", ... ... "Saturday") 
 
 
CInt() 
 
函数将一个表达式转化为数字类型 
 
表达式 CInt(expression) 
 
允许数据类型: 任何有效的字符均可 
 
实例: <% 
 
f = "234" 
 
response.write cINT(f) + 2 
 
%> 
 
返回结果: 236 
 
转化字符"234"为数字"234",如果字符串为空,则返回0值 
 
 
CreateObject() 
 
函数建立和返回一个已注册的ACTIVEX组件的实例。 
 
表达式 CreateObject(objName) 
 
允许数据类型: objName 是任何一个有效、已注册的ACTIVEX组件的名字. 
 
实例: <% 
 
Set con = Server.CreateObject("ADODB.Connection") 
 
%> 
 
 
CStr() 
 
函数转化一个表达式为字符串. 
 
表达式 CStr(expression) 
 
允许数据类型: expression 是任何有效的表达式。 
 
实例: <% 
 
s = 3 + 2 
 
response.write "The 返回结果 is: " & cStr(s) 
 
%> 
 
返回结果: 转化数字“5”为字符“5”。 
 
 
Date() 
 
函数返回当前系统日期. 
 
表达式 Date() 
 
允许数据类型: None. 
 
实例: <%=Date%> 
 
返回结果: 9/9/00 
 
 
DateAdd() 
 
函数返回一个被改变了的日期。 
 
表达式 DateAdd(timeinterval,number,date) 
 
允许数据类型: 
timeinterval is the time interval to add; 
number is amount of time intervals to add; 
and date is the starting date. 
 
实例: <% 
 
currentDate = #9/9/00# 
 
newDate = DateAdd("m",3,currentDate) 
 
response.write newDate 
 
%> 
 
 
<% 
 
currentDate = #12:34:45 PM# 
 
newDate = DateAdd("h",3,currentDate) 
 
response.write newDate 
 
%> 
 
返回结果: 9/9/00 
 
3:34:45 PM 
 
"m" = "month"; 
 
"d" = "day"; 
 
If currentDate is in time format then, 
 
"h" = "hour"; 
 
"s" = "second"; 
 
 
DateDiff() 
 
函数返回两个日期之间的差值 。 
 
表达式 DateDiff(timeinterval,date1,date2 [, firstdayofweek [, firstweekofyear]]) 
 
允许数据类型: timeinterval 表示相隔时间的类型,如“M“表示“月”。 
 
实例: <% 
 
fromDate = #9/9/00# 
 
toDate = #1/1/2000# 
 
response.write "There are " & _ 
 
DateDiff("d",fromDate,toDate) & _ 
 
" days to millenium from 9/9/00." 
 
%> 
 
返回结果: 从9/9/00 到2000年还有 150 天. 
 
 
Day() 
 
函数返回一个月的第几日 . 
 
表达式 Day(date) 
 
允许数据类型: date 是任何有效的日期。 
 
实例: <%=Day(#9/9/00#)%> 
 
返回结果: 4 
 
 
FormatCurrency() 
 
函数返回表达式,此表达式已被格式化为货币值 
 
表达式 FormatCurrency(Expression [, Digit [, LeadingDigit [, Paren [, GroupDigit]]]]) 
 
允许数据类型: Digit 指示小数点右侧显示位数的数值。默认值为 -1,指示使用的是计算机的区域设置; LeadingDigit 三态常数,指示是否显示小数值小数点前面的零。

返回结果: False 
 
 
IsNumeric() 
 
函数判断一对象是否为数字,返回布尔值. 
 
表达式 IsNumeric(expression) 
 
实例: <% 
 
i = "345" 
 
response.write IsNumeric(i) 
 
%> 
 
返回结果: True 
 
就算数字加了引号,ASP还是认为它是数字。 
 
 
IsObject() 
 
函数判断一对象是否为对象,返回布尔值. 
 
表达式 IsObject(expression) 
 
实例: <% 
 
Set con = Server.CreateObject("ADODB.Connection") 
 
response.write IsObject(con) 
 
%> 
 
返回结果: True 
 
 
LBound() 
 
函数返回指定数组维的最小可用下标. 
 
表达式 Lbound(arrayname [, dimension]) 
 
实例: <% 
 
i = Array("Monday","Tuesday","Wednesday") 
 
response.write LBound(i) 
 
%> 
 
返回结果: 0 
 
 
LCase() 
 
函数 返回字符串的小写形式 
 
表达式 Lcase(string) 
 
实例: <% 
 
strTest = "This is a test!" 
 
response.write LCase(strTest) 
 
%> 
 
返回结果: this is a test! 
 
 
Left() 
 
函数返回字符串左边第length个字符以前的字符(含第length个字符). 
 
表达式 Left(string, length) 
 
实例: <% 
 
strTest = "This is a test!" 
 
response.write Left(strTest, 3) 
 
%> 
 
返回结果: Thi 
 
 
Len() 
 
函数返回字符串的长度. 
 
表达式 Len(string | varName) 
 
实例: <% 
 
strTest = "This is a test!" 
 
response.write Len(strTest) 
 
%> 
 
返回结果: 15 
 
 
LTrim() 
 
函数去掉字符串左边的空格. 
 
表达式 LTrim(string) 
 
实例: <% 
 
strTest = " This is a test!" 
 
response.write LTrim(strTest) 
 
%> 
 
返回结果: This is a test! 
 
 
Mid() 
 
函数返回特定长度的字符串(从start开始,长度为length). 
 
表达式 Mid(string, start [, length]) 
 
实例: <% 
 
strTest = "This is a test! Today is Monday." 
 
response.write Mid(strTest, 17, 5) 
 
%> 
 
返回结果: Today 
 
 
Minute() 
 
函数返回时间的分钟. 
 
表达式 Minute(time) 
 
实例: <%=Minute(#12:45:32 PM#)%> 
 
返回结果: 45 
 
 
Month() 
 
函数返回日期. 
 
表达式 Month(date) 
 
实例: <%=Month(#08/04/99#)%> 
 
返回结果: 8 
 
 
MonthName() 
 
函数返回指定月份 
 
表达式 MonthName(month, [, Abb]) 
 
实例: <%=MonthName(Month(#08/04/99#))%> 
 
返回结果: August 
 
 
Now() 
 
函数返回系统时间 
 
表达式 Now() 
 
实例: <%=Now%> 
 
返回结果: 9/9/00 9:30:16 AM 
 
 
Right() 
 
函数返回字符串右边第length个字符以前的字符(含第length个字符). 
 
表达式 Right(string, length) 
 
实例: <% 
 
strTest = "This is an test!" 
 
response.write Right(strTest, 3) 
 
%> 
 
返回结果: st! 
 
 
Rnd() 
 
函数产生一个随机数. 
 
表达式 Rnd [ (number) ] 
 
实例: <% 
 
Randomize()
Rnd() 
 
函数产生一个随机数. 
 
表达式 Rnd [ (number) ] 
 
实例: <% 
 
Randomize() 
response.write RND() 
 
%> 
 
返回结果: 任何一个在0 到 1 之间的数 
 
 
Round() 
 
函数返回按指定位数进行四舍五入的数值. 
 
表达式 Round(expression [, numRight]) 
 
实例: <% 
 
i = 32.45678 
 
response.write Round(i) 
 
%> 
 
返回结果: 32 
 
 
Rtrim() 
 
函数去掉字符串右边的字符串. 
 
表达式 Rtrim(string) 
 
实例: <% 
 
strTest = "This is a test!! " 
 
response.write RTrim(strTest) 
 
%> 
 
返回结果: This is a test!! 
 
 
Split() 
 
函数将一个字符串分割并返回分割结果 
 
表达式 Split (S[,d]) 
 
实例:<%V= Split(A,B,C) 
 
For i = 0 To UBound(V) 
 
Response.Write V(i) 
 
Next 
 
%> 
 
返回结果: A B C 
 
 
Second() 
 
函数返回秒. 
 
表达式 Second(time) 
 
实例: <%=Second(#12:34:28 PM#)%> 
 
返回结果: 28 
 
 
StrReverse() 
 
函数反排一字符串 
 
表达式 StrReverse(string) 
 
实例: <% 
 
strTest = "This is a test!!" 
 
response.write StrReverse(strTest) 
 
%> 
 
返回结果: !!tset a si sihT 
 
 
Time() 
 
函数返回系统时间. 
 
表达式 Time() 
 
实例: <%=Time%> 
 
返回结果: 9:58:28 AM 
 
 
Trim() 
 
函数去掉字符串左右的空格. 
 
表达式 Trim(string) 
 
实例: <% 
 
strTest = " This is a test!! " 
 
response.write Trim(strTest) 
 
%> 
 
返回结果: This is a test!! 
 
 
UBound() 
 
函数返回指定数组维数的最大可用下标>. 
 
表达式 Ubound(arrayname [, dimension]) 
 
实例: <% 
 
i = Array("Monday","Tuesday","Wednesday") 
 
response.write UBound(i) 
 
%> 
 
返回结果: 2 
 
 
UCase() 
 
函数返回字符串的大写形式. 
 
表达式 UCase(string) 
 
允许数据类型: 
 
实例: <% 
 
strTest = "This is a test!!" 
 
response.write UCase(strTest) 
 
%> 
 
返回结果: THIS IS A TEST!! 
 
 
VarType() 
 
函数返回指示变量子类型的值 
 
表达式 VarType(varName) 
 
实例: <% 
 
i = 3 
 
response.write varType(i) 
 
%> 
 
返回结果: 2(数字)详见"asp常数" 
 
 
WeekDay() 
 
函数返回在一周的第几天. 
 
表达式 WeekDay(date [, firstdayofweek]) 
 
实例: <% 
 
d = #9/9/00# 
 
response.write Weekday(d) 
 
%> 
 
返回结果: 4(星期三) 
 
 
WeekDayName() 
 
函数返回一周第几天的名字. 
 
表达式 WeekDayName(weekday [, Abb [, firstdayofweek]]) 
 
实例: <% 
 
d = #9/9/00# 
 
response.write WeekdayName(Weekday(d)) 
 
%> 
 
返回结果: Wednesday 
 
 
Year() 
 
函数返回当前的年份. 
 
表达式 Year(date) 
 
实例: <%=Year(#9/9/00#)%> 
 
返回结果: 1999

参与讨论 5人

回复
  • 回复 2012/4/8 17:27:57 . sowhy 2楼
  • 很好!    

  • 回复 2012/4/8 17:35:34 . sowhy 3楼
  • very good!

  • 回复 2012/4/8 17:40:43 . sowhy 4楼
  • very good!

  • 回复 2012/4/8 17:47:19 . 黑蚂蚁 5楼
  • 回复 2012/4/8 17:49:08 . 黑蚂蚁 6楼
  • 添加一条新的回复

    返回列表
  • 验证码: 验证码
  • HI,欢迎来到SEMCMS外贸网站管理系统
  • 注册 登录
  • SEMCMS公众号扫一扫加关注
    及时了解系统更新情况
  • SEMCMS公众号扫一扫加关注