It's well-tested class for concatenating strings like:
but much much more faster than VB runtime do it.
Cases when it is needed sometimes:
Well, e.g., I'm using it to prepare some really huge logs of program in a single 'String' variable (e.g. up to 1 MB.) rather then writing them line by line to file (for performance acceleration purposes, if debug mode of my app. is disabled).
Don't know what else good cases. Better, don't store large data in this way, use suitable tools: arrays, databases ...
Using examples:
Result:
All data: Very many pieces of data
Len of data: 24
New data: many pieces of data
New data: Not many pieces of data
New data: How many pieces of data
New data: Anew
Len of data: 0
Copyrights: VolteFace (Fork by Dragokas)
Code:
s = s & "one line"
s = s & "two line"
...
s = s & "N line"
Cases when it is needed sometimes:
Well, e.g., I'm using it to prepare some really huge logs of program in a single 'String' variable (e.g. up to 1 MB.) rather then writing them line by line to file (for performance acceleration purposes, if debug mode of my app. is disabled).
Don't know what else good cases. Better, don't store large data in this way, use suitable tools: arrays, databases ...
Using examples:
Code:
Private Sub Form_Load()
'init
Dim sb As clsStringBuilder
Set sb = New clsStringBuilder
'concatenation
sb.Append "Very "
sb.Append "many "
sb.Append "pieces "
sb.Append "of data"
'result
Debug.Print "All data: "; sb.ToString
Debug.Print "Len of data: "; sb.length
'removing 5 characters from position # 0
sb.Remove 0, 5
Debug.Print "New data: "; sb.ToString
'inserting string in position # 0
sb.Insert 0, "Not "
Debug.Print "New data: "; sb.ToString
'overwrite part of the text from position # 0 (same like MID(str,x) = "...")
sb.Overwrite 0, "How"
Debug.Print "New data: "; sb.ToString
'replacing the data (same as Clear + Append)
sb.StringData = "Anew"
Debug.Print "New data: "; sb.ToString
'clear all data
sb.Clear
Debug.Print "Len of data: "; sb.length
'when finishing work with class
Set sb = Nothing
Unload Me
End Sub
Quote:
All data: Very many pieces of data
Len of data: 24
New data: many pieces of data
New data: Not many pieces of data
New data: How many pieces of data
New data: Anew
Len of data: 0