热门文章
 
在 VBScript 中使用
生成目录树结构的类
远程获取类Asp xmlHt
遭遇ASP类的事件设计
asp类方法初探(广告流量统
硬盘文件搜索代码(ASP类)
asp:debug类
ASP中一个字符串处理类
操作xml的类
读取XML的类 XmlRea
 推荐文章
 
异常类Exception
我眼中的ASP新框架
asp类方法初探(广告流量统
硬盘文件搜索代码(ASP类)
远程获取类Asp xmlHt
ASP中一个字符串处理类
Cookie,Session
代替缓存使用的ini类
分页类Pager
生成目录树结构的类
文件操作类
常用的工具类Utility
输入验证类Validator
asp:debug类
参考c#中的ArrayLis
用MVC模型引导你的WEB设
 
你现在的位置:您现在的位置是: 中国ASP>>ASP教程>>asp类
常用的工具类Utility

常用的工具类Utility:
<%
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 Each 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
%>

相关信息:

生成目录树结构的类
在 VBScript 中使用对象
远程获取类Asp xmlHttp
遭遇ASP类的事件设计
asp类方法初探(广告流量统计系统实践)
硬盘文件搜索代码(ASP类)
asp:debug类
ASP中一个字符串处理类

 

中国ASP技术 ASP.ORG.CN 版权所有 2004-2008