5D艺术网首页
商城
|
资讯
|
作品
|
博客
|
教程
|
论坛
登录
注册
加为好友
发短消息
来自:
性别:秘密
最后登录:2007-04-12
http://Xmercy.5d.cn/
首页
|
新闻
|
话题
|
博客
|
相册
|
艺术作品
|
社交关系
|
留言板
|
社交圈
2005/10/30 | 敝帚自珍:ASP工具类(字符串处理)Utility
类别(Develop)
|
评论
(0)
|
阅读(104)
|
发表于 16:08
根据项目需求写的,方法还不全。不过可以按需添加。
<%
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
Public Function getHostName ()
Dim hostName
hostName = Request.ServerVariables("HTTP_HOST")
If Not IsNull(Request.ServerVariables("HTTP_X_FORWARDED_HOST")) Then
If Len(Trim(Request.ServerVariables("HTTP_X_FORWARDED_HOST"))) > 0 Then
hostName = Request.ServerVariables("HTTP_X_FORWARDED_HOST")
End If
End If
getHostName = hostName
End Function
End Class
%>
<%
Dim Util : Set Util = New Utility
%>
0
评论
Comments
日志分类
首页
[66]
Develop
[14]
Plus
[3]
Melody
[7]
Essay
[38]
Archive
[4]