ASP下的StringBuilder类

2012-03-20  金城  1933

<%
'ASP下的StringBuilder类
' 说明:ASP下的StringBuilder类
' 作者:Tank
' 日期:2007-09-28
' 最后更新:2009-02-28
' 描述:用于快速组合大量字符

Class Cls_StringBuilder
private arr()
private arrLen
private arrCurLen
private arrStep

' 初始化操作
Private Sub Class_Initialize
Step = 64
Call Clear()
End Sub

' 资源释放
Private Sub Class_Terminate()
Redim arr(0)
End Sub

' 设置数组步进长度
public property Let Step(Value)
arrStep = Value
end property

' 获取数组步进长度
public property Get Step()
Step = arrStep
end property

' 返回数组长度
public property Get Count()
Count = arrCurLen
end property

' 返回 splitter 分隔的字符串
public function toString(splitter)
if Count = 0 then
toString = ""
exit function
end if

' 返回时重定义数组长度为实际长度
if Count <= arrLen then
Redim Preserve arr(Count - 1)
arrLen = Count
end if
toString = join(arr,splitter)
end function

' 追加字符串
public function Append(byval s)
arrCurLen = arrCurLen + 1
if arrCurLen >arrLen then
arrLen = arrLen + Step
Redim Preserve arr(arrLen)
end if

arr(arrCurLen - 1) = s
end function

' 插入字符串
public function Insert(byval i,byval s)
dim j
arrCurLen = arrCurLen + 1
if arrCurLen >arrLen then
arrLen = arrLen + Step
Redim Preserve arr(arrLen)
end if
for j=arrCurLen - 1 to i step -1
arr(j+1)=arr(j)
next
arr(i) = s
end function

' 清除所有字符串
public function Clear()
Redim arr(0)
arrLen = Step
arrCurLen = 0
Redim arr(arrLen)
end function
End Class
%>