Common Tool Class Utility

Source: Internet
Author: User
Tags strlen

<%
Class Utility

Private Reg

Public Function HTMLEncode (STR)
If IsNull (str) or IsEmpty (str) or str = "" Then
HTMLEncode = ""
Else
Dim s:s = Str
s = Replace (S, "<", "<")
s = Replace (S, ">", ">")
s = Replace (S, "", "")
s = Replace (S, vbCrLf, "<br/>")
HTMLEncode = S
End If
End Function

Public Function Htmlfilter (ByVal Code)
If IsNull (code) Or IsEmpty (code) Then Exit Function
With Reg
. Global = True
. Pattern = "<[^>]+?>"
End With
Code = Reg.replace (Code, "")
Htmlfilter = Code
End Function

Public Function Limit (ByVal Str, ByVal Num)
Dim Strlen:strlen = Len (STR)
If StrLen * 2 <= Num Then
Limit = Str
Else
Dim Strrlen
Call Rlen (STR, Strrlen)
If Strrlen <= Num Then
Limit = Str
Else
Dim I
Dim Restr
If StrLen > Num * 2 Then
i = Num \2
Restr = Left (Str, i)
Call Rlen (RESTR, Strrlen)
While Strrlen < Num
i = i + 1
Restr = Left (Str, i)
Call Rlen (RESTR, Strrlen)
Wend
Else
i = StrLen
RESTR = Str
Call Rlen (RESTR, Strrlen)
While Strrlen > Num
i = I-1
Restr = Left (Str, i)
Call Rlen (RESTR, Strrlen)
Wend
End If
Call Rlen (Right (restr, 1), Strrlen)
If Strrlen > 1 Then
Limit = Left (Restr, i-1) & "..."
Else
Limit = Left (Restr, i-2) & "..."
End If
End If
End If
End Function

Public Function Encode (ByVal Str)
str = Replace (str, "" "", "" ")
str = Replace (str, "" "," "")
Encode = Str
End Function

Public Function Encodeall (ByVal Str)
Dim M, MS
Reg.pattern = "[\x00-\xff]"
Set MS = Reg.execute (STR)
For all M in MS
str = Replace (str, m.value, "&#" & Asc (M.value) & ";")
Next
Encodeall = Str
End Function

Private Sub Class_Initialize ()
Set Reg = New RegExp
Reg.global = True
End Sub
Private Sub Class_Terminate ()
Set Reg = Nothing
End Sub

Public Sub Rlen (ByRef Str, ByRef Rl)
With Reg
. pattern = "[^\x00-\xff]"
Rl = Len (. Replace (Str, ".."))
End With
End Sub

End Class
%>
<%
Dim util:set Util = New Utility
%>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.