StringBuilder

While using Response.write is far away faster than concatenating strings, sometimes you need to store the entire output before printing it.  That’s when a special designed string builder class is required.

About

Summary
While using Response.write is far away faster than concatenating strings, sometimes you need to store the entire output before printing it.
Buffer growth size.
Clear the string builder data.
Concatenate the fragments into a string.

Properties

growth_size

Buffer growth size.

Contains

(long) The growth size

Functions

reset

public function reset()

Clear the string builder data.

toString

public function toString()

Concatenate the fragments into a string.  Note that since VBScript does not provide a mid assignment statement, we are using the join function which is faster than straight concatenation, but does not scale well when called to concatenate arrays with a large number of elements.

Returns

(string) concatenated string

Example

dim sStdConcat, stdConcat_a, stdConcat_b
dim sSbConcat, sbConcat_a, sbConcat_b
dim i
 
stdConcat_a = timer
sStdConcat = ""
for i = 0 to 10000
    sStdConcat = sStdConcat & "This is an average fragment of text."
next
stdConcat_b = timer
 
sbConcat_a = timer
set sSbConcat = new StringBuilder
for i = 0 to 10000
    sSbConcat.append("This is an average fragment of text.")
next
set sSbConcat = nothing
sbConcat_b = timer
 
Response.write("While the required time to concatenate the string with the & operator is " & (stdConcat_b - stdConcat_a) & ", the time consumed by the StringBuilder is " & (sSbConcat_b - sSbConcat_a) & ".")
public function reset()
Clear the string builder data.
public function toString()
Concatenate the fragments into a string.