'StringBuffer Class: Option Public Option Explicit Class StringBuffer '** This is a class that provides basic StringBuffer functionality '** in LotusScript (which is more efficient if you are doing a '** whole bunch of String concatenations). You should probably '** add some error handling, and take a look at the methods in '** the Java StringBuffer class to see if there's any other '** functionality you'd like to emulate. '** '** version 1.0 '** Julian Robichaux -- http://www.nsftools.com '** August 9, 2004 Private tempArray() As String Private buffer As String Private pos As Integer Private startSize As Integer Private upperB As Integer Private maxSize As Integer Sub New (startSize As Integer) '** startSize is just the initial size of the internal array, '** which will be doubled every time you run out of '** space in the internal array (16 is a good number '** to use here) Me.startSize = startSize '** if you have to use r5Join in the toString method, '** set maxSize to ~ 3000; otherwise (if you're using '** the Join function in Notes 6 or higher) you can set '** maxSize as big of an Integer as you'd like (I use 32000) maxSize = 32000 Me.resetArray(startSize) End Sub '** return the contents of the StringBuffer as a String Public Function toString () As String '** if this has to be compatible with Notes R5 or lower, use: 'toString = buffer & r5Join(tempArray, "") '** for Notes 6 and higher, you can use: toString = buffer & Join(tempArray, "") End Function '** append any kind of variable that can be converted to a String Public Sub append (v As Variant) If (pos > upperB) Then buffer = Me.toString Me.resetArray(Clng(upperB) * 2) End If tempArray(pos) = Cstr(v) pos = pos + 1 End Sub '** use this if you want to clear the StringBuffer Public Sub erase () Me.resetArray(startSize) buffer = "" End Sub Private Sub resetArray (size As Long) Select Case size Case Is < 0 : upperB = 0 Case Is > maxSize : upperB = maxSize Case Else : upperB = size End Select Redim tempArray(0 To upperB) As String pos = 0 End Sub Private Function r5Join (arr As Variant, delim As String) As String '** this is a version of the ND6 Join function (also called the '** Implode function), for use with Notes R5 or lower On Error Goto processError Dim i As Integer Dim lb As Integer, ub As Integer Dim delimLen As Integer Dim returnString As String lb = Lbound(arr) ub = Ubound(arr) For i = lb To ub r5Join = r5Join + Cstr(arr(i)) + delim Next processError: Exit Function End Function End Class Sub Initialize Dim sb As New StringBuffer(16) Dim s As String Dim startTime As Single Dim i As Long '** this is a test of the StringBuffer class '** REMOVE ALL THIS IF YOU USE THE CODE IN PRODUCTION startTime = Timer() For i = 0 To 100000 sb.append("a") Next Print "Final string buffer length = " & Len(sb.toString) & ". Timer = " & (Timer() - startTime) & " sec." startTime = Timer() For i = 0 To 100000 s = s & "a" Next Print "Final string length = " & Len(s) & ". Timer = " & (Timer() - startTime) & " sec." End Sub