%
Class appendString
Private arrIndex, arrUbound, arrList()
Private Sub Class_Initialize()
‘分配10長度
redim arrList(10)
‘當前長度
arrIndex = 0
'每次擴展長度
arrUbound = 10
End Sub
Private Sub Class_Terminate()
'釋放所有數(shù)組,再次使用時,需要重新分配
Erase arrList
End Sub
‘設(shè)置值并動態(tài)擴展長度
Public Default Sub Add(value)
arrList(arrIndex) = value
arrIndex = arrIndex + 1
if arrIndex > arrUbound then
arrUbound = arrUbound + 50
redim preserve arrList(arrUbound)
end if
End Sub
'返回字符串
Public Function getString(splitString)
redim preserve arrList(arrIndex - 1)
getString = join(arrList,splitString)
End Function
End Class
'調(diào)用方法
Set StringClass = New appendString
StringClass.add("我")
StringClass.add("愛")
StringClass.add("編")
StringClass.add("程")
OutputString = StringClass.getString("") '打印結(jié)果是:我愛編程
%>