从TSYS通用函数库中提取出了一些有用的函数

来源:互联网 发布:path finder for mac 编辑:程序博客网 时间:2024/04/29 22:05

<%
    '函数:过滤Html标签
    '参数:字符串
    '返回:过滤后字符串
    Public Function FilterHtml(str)
        Dim regEx
        '创建正则对象
        Set regEx = New RegExp
        regEx.IgnoreCase = True
        regEx.Global = True
        regEx.MultiLine = True

        regEx.Pattern = "<.+?>"
        FilterHtml = regEx.Replace(str,"")
        Set regEx = Nothing
    End Function

    '函数:验证邮件地址格式
    '参数:字符串
    '返回:bool (true:正确)
    Public Function CheckEmail(str)
        Dim regEx
        '创建正则对象
        Set regEx = New RegExp
        regEx.IgnoreCase = True
        regEx.Global = True
        regEx.MultiLine = True

        regEx.Pattern = "^/w+((-/w+)|(/./w+))*/@[A-Za-z0-9]+((/.|-)[A-Za-z0-9]+)*/.[A-Za-z0-9]+$"
        CheckEmail = regEx.Test(str)
        Set regEx = Nothing
    End Function

    '函数:是否为服务实际路径
    Public Function IsReallyPath(str)
        Dim regEx
        '创建正则对象
        Set regEx = New RegExp
        regEx.IgnoreCase = True
        regEx.Global = True
        regEx.MultiLine = True

        regEx.Pattern = "^[c-z]/:.+$"
        IsReallyPath = regEx.Test(str)
        Set regEx = Nothing
    End Function

    '函数:判断路径类型
    '返回:
    '   1   物理路径
    '   2   站点虚路径
    '   3   网络路径
    Public Function ChkPathType(strPath)
        Dim regEx
        '创建正则对象
        Set regEx = New RegExp
        regEx.IgnoreCase = True
        regEx.Global = True
        regEx.MultiLine = False

        regEx.Pattern = "^[c-z]{1,1}/:.+$"
        If regEx.Test(strPath) Then
            ChkPathType = 1
            Exit Function
        End If

        regEx.Pattern = "^(?:http|https){1,1}/:.+$"
        If regEx.Test(strPath) Then
            ChkPathType = 3
            Exit Function
        End If

        ChkPathType = 2

        Set regEx = Nothing
    End Function

    '函数:字符串截断(可识别中英文)
    '参数:预截字符串,长度
    '返回:截断后的字符串
    Public Function CutStr(str,strlen)
        DIM l,t,c,m_i
        l=len(str)
        t=0
        For m_i = 1 To l
            c = Abs(Asc(Mid(str,m_i,1)))
            If c > 255 Then
                t = t+2
            Else
                t = t+1
            End If
   
            If t >= strlen Then
                CutStr = left(str,m_i) & "..."
                exit for
            Else
                CutStr = str
            End if
        Next
    End Function

    '函数:转义javascript特殊字符
    '参数:html串
    '返回:转义后的串
    Public Function HTMLToJS(strHtml)
        If Trim(strHtml)="" Then
            HTMLToJS=""
            Exit Function
        End If

        strHtml=Replace(strHtml,"/","//")
        strHtml=Replace(strHtml,"""","/""")
        strHtml=Replace(strHtml,vbCrLf,"")

        HTMLToJS=strHtml
    End Function

    '函数:时间格式化
    '参数:时间,格式模板
    '返回:格式化后的字符串
    '备注:格式化关键词详解:
    '   "{Y}" : 4位年
    '   "{y}" : 2位年
    '   "{M}" : 不补位的月
    '   "{m}" : 补位的月,如03,01
    '   "{D}" : 不补位的日
    '   "{d}" : 补位的日
    '   "{H}" : 不补位的小时
    '   "{h}" : 补位的小时
    '   "{MI}": 不补位的分钟
    '   "{mi}": 补位的分钟
    '   "{S}" : 不补位的秒
    '   "{s}" : 补位的秒
    Public Function FormatMyDate(myDate,Template)
        If Not IsDate(myDate) Or Template = "" Then
            FormatMyDate = Template
            Exit Function
        End If

        Dim mYear,mMonth,mDay,mHour,mMin,mSec
            mYear = Year(myDate)
            mMonth = Month(myDate)
            mDay = Day(myDate)
            mHour = Hour(myDate)
            mMin = Minute(myDate)
            mSec = Second(myDate)

        Template = Replace(Template,"{Y}",Year(myDate))
        Template = Replace(Template,"{y}",Right(Year(myDate),2))
        Template = Replace(Template,"{M}",Month(myDate))
        Template = Replace(Template,"{m}",Right("00" & Month(myDate),2))
        Template = Replace(Template,"{D}",Day(myDate))
        Template = Replace(Template,"{d}",Right("00" & Day(myDate),2))
        Template = Replace(Template,"{H}",Hour(myDate))
        Template = Replace(Template,"{h}",Right("00" & Day(myDate),2))
        Template = Replace(Template,"{MI}",Minute(myDate))
        Template = Replace(Template,"{mi}",Right("00" & Minute(myDate),2))
        Template = Replace(Template,"{S}",Second(myDate))
        Template = Replace(Template,"{s}",Right("00" & Second(myDate),2))

        FormatMyDate = Template
    End Function

    '函数:通用信息提示框
    '参数:
    '   提示内容
    '   返回地址,详细值类型如下:
    '       "#"      只提示,其它不做任何操作
    '       "BACK"   提示后返回前一页
    '       "CLOSE"  提示后关闭窗口
    '       "网址"    提示后返回指定页面
    '   是否父窗口
    Public Function Alert(str,backUrl,TopWindow)

        If str <> "" Then
            Response.Write "<script>alert(""" & str & """);"
        End If

        Dim WinName
        If TopWindow = 1 Then
            WinName = "top"
        Else
            WinName = "self"
        End If

        Select Case backUrl
            Case "#"
            Case "BACK"
                Response.Write WinName & ".history.back();"
            Case "CLOSE"
                Response.Write "window.close();"
            Case Else
                If backUrl <> "" Then
                    Response.Write WinName & ".location.href = """ & backUrl & """;"
                End If
        End Select
        Response.Write "</script>"
    End Function

    '函数:创建完整目录
    '参数:目录串
    Public Function CreateFolder(strPath)
        strPath = Replace(strPath,"/", "/")
        arrPath = Split(strPath, "/")
        Dim Fso, I, tmpPath, arrPath
        Set Fso = Server.CreateObject(Cfg.FileSystemObject_Name)
        tmpPath = arrPath(0)
        For I=1 To UBound(arrPath)
            tmpPath  = tmpPath & "/" & arrPath(I)
            If Not Fso.FolderExists(tmpPath) Then
                Fso.CreateFolder tmpPath
            End If
        Next
    End Function

    Public Function FormatEmpty(str, fstr)
        If IsNull(str) Or str = "" Then
            FormatEmpty = fstr
        Else
            FormatEmpty = str
        End If
    End Function


%>

原创粉丝点击