ASP常用函数介绍

来源:互联网 发布:和男友逛街知乎 编辑:程序博客网 时间:2024/05/16 15:57

.函數Lcase()
功能:將一字符類型變量的字符全部變換小寫字符.
格式:Lcase(string)
參數:string是字串變量
例子:
<%
str="THIS is Lcase!"
response.write Lcase(str)
%>
結果:this is lcase!
.函數left()
功能:截取一個字符串的前部分;
格式:left(string,length)
參數:string字符串,length截取的長度.
例子: <% =left("this is a test!",6) %>
結果:this i
.函數len()
功能:返回字符串長度或者變量的字節長度
格式:len(string |varname)
參數:string字符串;varname任意的變量名稱
例子:
<%
strtest="this is a test!"
response.write left(strtest)
%>
結果:15
.函數ltrim()
功能:去掉字符串前的空格.
格式:ltrim(string)
參數:string 字串.
例子: <% =ltrim (" this is a test!")
結果:this is a test!
.函數Mid()
功能:從字串中截取字串.
格式:mid(string,start [,length])
參數:string字串,start截取的起點,length要截取的長度.
例子:
<%
strtest="this is a test, Today is Monday!"
response.write mid(strtest,17,5)
%>
結果:Today
.函數minute()
功能:返回一數值, 表示分鐘
格式:minute(time)
參數: time是時間變量
例子lt;% =minute(#12:23:34#) %>
結果:23
.函數month()
功能:返回一數值, 表示月份
格式:month(time)
參數:time是日期變量
例子<% =month(#08/09/99) %>
結果:9
.函數monthname()
功能:返回月份的字符串(名稱).
格式:Monthname(date [,abb])
參數:date是日期變量,abb=true時 則月份的縮寫,
例子:
<% =monthname(#4/5/99#) %>
結果:April
.函數Now()
功能:返回系統的當前時間和日期.
格式:now()
參數:無
例子:
<% =now() %>
結果: 05/10/00 8:45:32 pm
.函數: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.
.函數right()
功能:截取一個字符串的后部分
格式:right(string,length)
參數:string字符串,length截取的長度.
例子:
<%
strtest="this is a test!"
response.write right(strtest,3)
%>
結果:st!
.函數rnd()
功能:返回一個隨机數值
格式:rnd[(number)]
參數:number是任意數值.
例子:
<%
randomize()
response.write rnd()
%>
結果:0/1數值之一,無randomize(), 則不能產生隨机數.
.函數round()
功能:完整數值
格式:round(expression[,numright])
參數:expression數字表達式;numright任意選項.
例子:
<%
i=12.33654
response.write round(i)
%>
結果: 12
.函數rtrim()
功能:去掉字符串后的空格.
格式:rtrim(string)
參數:string 是字串
例子:
<%
response.write rtrim("this is a test! ")
%>
結果:this is a test!
.函數second()
功能:返回一個整數值.
格式:second(time)
參數:time是一個有效的時間表達式;
例子lt;% =second(# 12:28:30#) %>
結果:30
.函數strReverse()
功能:返回与原字串排列逆向的字串.
格式:strreverse(string)
參數:string是字串
例子<% =strreverse("this is a test!")
結果:!tset a si siht
.函數time()
功能:返回當前系統的時間值.
格式:time()
參數:無
結果:9:58:28 Am
.函數trim()
功能:刪去字符串前,后的空格.
格式:trim(string)
參數:string 字串.
例子:
<%
strtest=" this is a test! "
response.write trim(strtest)
%>
結果:this is a test!
.函數UBound()
功能:返回一個數組的上界.
格式:Ubound(expression [,dimension])
參數:expression 是數組表達式/數組變量,dimension 是任意項
例子:
<%
i = array("1","2","3")
response.write ubound(i)
%>
結果: 2
.函數:UCase()
功能:將一字符類型變量的字符全部變換成大寫字符.
格式:Ucase(string)
參數:string是字串變量
例子:
<%
str="THIS is Lcase!"
response.write Lcase(str)
%>
結果:THIS IS LCASE!
.函數Vartype()
功能:返回變量的常量代碼(整數)
格式:Vartype(varname)
參數:varname是任何類型的變量名稱.
例子:
<%
i=5
response.write vartype(i)
%>
結果:2 (2表示整數,須要參考ASP常量代碼.)
.函數Weekday()
功能:返回一個整數,對應一周中的第几天.
格式:Weekday(date [,firstofweek])
參數:date為日期變量,firstofweek為任選項.
例子:
<%
d= # 5/9/00 #
response.write weekday(d) %>
結果:3(3 表示是星期二)
.函數weekdayname()
功能:返回字串,對應星期几.
格式:weekdayname(weekday[,abb[,firstdayofweek]])
參數:weekday為日期變量,abb,firstdayofweek為任選項.
例子:
<%
d = #8/4/99#
response.write weekdayname(d)
%>
結果: Wednesday
47.函數year()
功能:返回日期表達式所在的年份.
格式:year(date)
參數:date是有效的日期表達式
例子:
<% =year(#8/9/99#) %>
結果:1999

 

<script type="text/javascript"><!--google_ad_client = "pub-3795982983039684";google_ad_width = 468;google_ad_height = 60;google_ad_format = "468x60_as";google_ad_type = "text";google_ad_channel ="3581219955";google_color_border = "FFFFFF";google_color_link = "0000FF";google_color_bg = "FFFFFF";google_color_text = "000000";google_color_url = "008000";//--></script> <script src="http://pagead2.googlesyndication.com/pagead/show_ads.js" type="text/javascript"></script> <iframe name="google_ads_frame" marginwidth="0" marginheight="0" src="http://pagead2.googlesyndication.com/pagead/ads?client=ca-pub-3795982983039684&amp;dt=1162989294015&amp;lmt=1162989294&amp;prev_fmts=468x15_0ads_al_s%2C250x250_as&amp;format=468x60_as&amp;output=html&amp;channel=3581219955&amp;url=http%3A%2F%2Fwww.webdn.com%2Fweb_file%2Fprogram%2Fasp%2F0510060152%2F&amp;color_bg=FFFFFF&amp;color_text=000000&amp;color_link=0000FF&amp;color_url=008000&amp;color_border=FFFFFF&amp;ad_type=text&amp;ref=http%3A%2F%2Fwww.baidu.com%2Fs%3Fwd%3Dasp%2Btrim%25BA%25AF%25CA%25FD%26lm%3D0%26si%3D%26rn%3D10%26ie%3Dgb2312%26ct%3D0%26cl%3D3%26f%3D1%26rsp%3D2&amp;cc=429&amp;u_h=768&amp;u_w=1024&amp;u_ah=738&amp;u_aw=1024&amp;u_cd=32&amp;u_tz=480&amp;u_java=true" frameborder="0" width="468" scrolling="no" height="60" allowtransparency="allowtransparency"></iframe>