<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    posts - 189,comments - 115,trackbacks - 0

    ASP實用函數庫

    [ 2006-4-30 17:14:00 | By: 吉祥 ]
    <%
    '判斷文件名是否合法
    Function isFilename(aFilename)
    Dim sErrorStr,iNameLength,i
    isFilename=TRUE
    sErrorStr=Array("/","\",":","*","?","""","<",">","|")
    iNameLength=Len(aFilename)
    If iNameLength<1 or iNameLength=null Then
    isFilename=FALSE
    Else
    For i=0 To 8
    If instr(aFilename,sErrorStr(i)) Then
    isFilename=FALSE
    End If
    Next
    End If
    End Function

    '去掉字符串頭尾的連續的回車和空格
    function trimVBcrlf(str)
    trimVBcrlf=rtrimVBcrlf(ltrimVBcrlf(str))
    end function

    '去掉字符串開頭的連續的回車和空格
    function ltrimVBcrlf(str)
    dim pos,isBlankChar
    pos=1
    isBlankChar=true
    while isBlankChar
    if mid(str,pos,1)=" " then
    pos=pos+1
    elseif mid(str,pos,2)=VBcrlf then
    pos=pos+2
    else
    isBlankChar=false
    end if
    wend
    ltrimVBcrlf=right(str,len(str)-pos+1)
    end function

    '去掉字符串末尾的連續的回車和空格
    function rtrimVBcrlf(str)
    dim pos,isBlankChar
    pos=len(str)
    isBlankChar=true
    while isBlankChar and pos>=2
    if mid(str,pos,1)=" " then
    pos=pos-1
    elseif mid(str,pos-1,2)=VBcrlf then
    pos=pos-2
    else
    isBlankChar=false
    end if
    wend
    rtrimVBcrlf=rtrim(left(str,pos))
    end function

    '判斷Email是否有效,返回1表示正確
    Function isEmail(aEmail)
    Dim iLocat,v,iLength,i,checkletter
    If instr(aEmail,"@") = 0 or instr(aEmail,".") = 0 Then
    isEmail=0
    EXIT FUNCTION
    End If
    iLocat=instr(aEmail,"@")
    If instr(iLocat,aEmail,".")=0 or instr(iLocat+1,aEmail,"@")>0 Then
    isEmail=0
    EXIT FUNCTION
    End If
    If left(aEmail,1)="." or right(aEmail,1)="." or left(aEmail,1)="@" or right(aEmail,1)="@" Then
    isEmail=0
    EXIT FUNCTION
    End If
    v="1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_-.@"
    iLength=len(aEmail)
    For i=1 To iLength
    checkletter=mid(aEmail,i,1)
    If instr(v,checkletter)=0 Then
    isEmail=0
    EXIT FUNCTION
    End If
    Next
    isEmail=1
    End Function

    '測試用:顯示服務器信息
    Sub showServer
    Dim name
    Response.write "<Table border=1 bordercolor=lightblue CELLSPACING=0>"
    for each name in request.servervariables
    Response.write "<tr>"
    Response.write "<td>"&name&"</td>"
    Response.write "<td>"&request.servervariables(name)&"<br></td>"
    Response.write "</tr>"
    next
    Response.write "</table>"
    End Sub

    '測試用:顯示Rs結果集以及字段名稱
    Sub showRs(rs)
    Dim strTable,whatever
    Response.write "<center><table><tr>"
    for each whatever in rs.fields
    response.write "<td><b>" & whatever.name & "</B></TD>"
    next
    strTable = "</tr><tr><td>"&rs.GetString(,,"</td><td>","</tr><tr><td>"," ") &"</td></tr></table></center>"
    Response.Write(strTable)
    End Sub

    '用HTML格式顯示文本
    Function txt2Html(str)
    if isnull(str) then
    txt2Html=""
    exit Function
    end if
    str=Replace(str,chr(34),""")
    str=Replace(str,"<","<")
    str=Replace(str,">",">")
    str=Replace(str,chr(13)+chr(10),"<br>")
    str=Replace(str,chr(9)," ")
    str=Replace(str," "," ")
    txt2Html=str
    End Function

    '測試用:顯示調試錯誤信息
    Sub showError
    Dim sErrMsg
    sErrMsg=Err.Source&" "&Err.Description
    Response.write "<center>"&sErrMsg&"</center>"
    Err.clear
    End Sub

    '顯示文字計數器
    Sub showCounter
    Dim fs,outfile,filename,count
    filename=server.mappath("count.txt")
    Set fs = CreateObject("Scripting.FileSystemObject")
    If fs.fileExists(filename) Then
    Set outfile=fs.openTextFile(filename,1)
    count=outfile.readline
    count=count+1
    Response.write "<center>瀏覽人次:"&count&"<center>"
    outfile.close
    Set outfile=fs.CreateTextFile(filename)
    outfile.writeline(count)
    Else
    Set outfile=fs.openTextFile(filename,8,TRUE)
    count=0
    outfile.writeline(count)
    END IF
    outfile.close
    set fs=nothing
    End Sub
    %>

    Array()
     FUNCTION: 返回一個數組
     SYNTAX: Array(list)
     ARGUMENTS: 字符,數字均可
     EXAMPLE: <%
    Dim myArray()
    For i = 1 to 7
      Redim Preserve myArray(i)
      myArray(i) = WeekdayName(i)
    Next
    %>
     RESULT: 建立了一個包含7個元素的數組myArray
    myArray("Sunday","Monday", ... ... "Saturday")
     
    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()
     ARGUMENTS: None.
     EXAMPLE: <%=Date%>
     RESULT: 8/4/99
     
    DateAdd()
     FUNCTION: 返回一個被改變了的日期。
     SYNTAX: DateAdd(timeinterval,number,date)
     ARGUMENTS: timeinterval is the time interval to add; number is amount of
    time intervals to add; and date is the starting 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)%>  <%=int(-3.33)%>
     RESULT: 32  -4
     
    IsArray()
     FUNCTION: 判斷一對象是否為數組,返回布爾值 .
     SYNTAX: IsArray(name)
     ARGUMENTS: 
     EXAMPLE: <%
    strTest = "Test!"
    response.write IsArray(strTest)
    %>
     RESULT: False
     
    IsDate()
     FUNCTION: 判斷一對象是否為日期,返回布爾值
     SYNTAX: IsDate(expression)
     ARGUMENTS: expression is any valid 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()
     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(date)
     ARGUMENTS: date is any valid date expression.
     EXAMPLE: <%=Month(#08/04/99#)%>
     RESULT: 8
     
    MonthName()
     FUNCTION: Returns a string identifying the specified month.
     SYNTAX: MonthName(month, [, Abb])
     ARGUMENTS: month is the numeric representation for a given month; Abb
    (optional) is a boolean value used to display month abbreviation. True
    will display the abbreviated month name and False (default) will not show
    the abbreviation.
     EXAMPLE: <%=MonthName(Month(#08/04/99#))%>
     RESULT: August
     
    Now()
     FUNCTION: Returns the current system date and time.
     SYNTAX: Now()
     ARGUMENTS: None
     EXAMPLE: <%=Now%>
     RESULT: 8/4/99 9:30:16 AM
     
    Replace()
     FUNCTION: Returns a string in which a specified sub-string has been
    replaced with another substring a specified number of times.
     SYNTAX: Replace(strToBeSearched, strSearchFor, strReplaceWith [, start
    ][, count ][, compare]]])
     ARGUMENTS: strToBeSearched is a string expression containing a sub-
    string to be replaced; strSearchFor is the string expression to search for
    within strToBeSearched; strReplaceWith is the string expression to replace
    sub-string strSearchFor; start (optional) is the numeric character
    position to begin search; count (optional) is a value indicating the
    comparision constant.
     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()
    response.write RND()
    %>
     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()
     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
    posted on 2006-05-02 22:58 MEYE 閱讀(383) 評論(0)  編輯  收藏

    只有注冊用戶登錄后才能發表評論。


    網站導航:
     
    主站蜘蛛池模板: 亚洲综合国产精品| 亚洲熟妇无码一区二区三区导航| 叮咚影视在线观看免费完整版| 久久久久亚洲av无码专区蜜芽| 亚洲视频免费在线播放| 亚洲乱码中文字幕在线| 国产亚洲午夜高清国产拍精品| www亚洲精品少妇裸乳一区二区| 亚洲国产高清视频在线观看| A在线观看免费网站大全| 国产成人精品亚洲| 久久精品国产亚洲网站| 久久精品无码一区二区三区免费| 香蕉97碰碰视频免费| 99久久精品国产亚洲| 免费一级肉体全黄毛片| 美女内射毛片在线看免费人动物| 亚洲AV无码成人精品区日韩 | 黄页免费在线观看 | 黄桃AV无码免费一区二区三区| 亚洲高清在线mv| 91视频免费网址| 日韩毛片一区视频免费| 亚洲手机中文字幕| 中文字幕人成人乱码亚洲电影 | 美女视频黄a视频全免费网站一区 美女视频黄a视频全免费网站色 | 182tv免费视频在线观看| 亚洲午夜精品久久久久久app| 亚洲乱色熟女一区二区三区丝袜| 无码视频免费一区二三区| 亚洲精品久久无码av片俺去也 | 亚洲国产综合AV在线观看| 亚洲av不卡一区二区三区| 免费少妇a级毛片| 成年女人毛片免费视频| 久久精品乱子伦免费| 欧洲乱码伦视频免费国产| 在线观看亚洲AV日韩A∨| 亚洲伦另类中文字幕| 亚洲自偷自偷图片| 亚洲?V无码乱码国产精品|