StringBuilder Functions

A StringBuilder provides efficient string building when concatenating many pieces together. Use GetStringBuilder to create one, build the string using SBAppend and other functions, then call SBToString to get the final result.

This avoids creating a large number of intermediate strings compared to using & in a loop.


GetStringBuilder

GetStringBuilder()

Creates and returns a new empty StringBuilder object.

Returns: StringBuilder

Examples:

Dim sb = GetStringBuilder()

SBAppend

SBAppend(StringBuilder, Value)

Appends Value (converted to a string) to the end of the StringBuilder.

Parameter Description
StringBuilder The StringBuilder to append to
Value The value to append

Returns: Boolean (True on success)

Examples:

SBAppend(sb, "Hello")
SBAppend(sb, " ")
SBAppend(sb, "World")

SBClear

SBClear(StringBuilder)

Removes all content from the StringBuilder, resetting it to empty.

Returns: Boolean (True on success)

Examples:

SBClear(sb)

SBInsert

SBInsert(StringBuilder, Index, Value)

Inserts Value into the StringBuilder at the specified zero-based Index.

Parameter Description
StringBuilder Target StringBuilder
Index Zero-based position to insert at
Value The value to insert

Returns: Boolean (True on success)

Examples:

' sb contains "Hello World"
SBInsert(sb, 5, ",")    ' "Hello, World"

SBRemove

SBRemove(StringBuilder, StartIndex, Length)

Removes Length characters starting at the zero-based StartIndex.

Parameter Description
StringBuilder Target StringBuilder
StartIndex Zero-based starting position
Length Number of characters to remove

Returns: Boolean (True on success)

Examples:

' sb contains "Hello World"
SBRemove(sb, 5, 6)    ' "Hello"

SBReplace

SBReplace(StringBuilder, Find, Replace)

Replaces all occurrences of Find within the StringBuilder with Replace.

Parameter Description
StringBuilder Target StringBuilder
Find The substring to find
Replace The replacement string

Returns: Boolean (True on success)

Examples:

SBReplace(sb, "World", "There")

SBToString

SBToString(StringBuilder)

Returns the current contents of the StringBuilder as a String.

Returns: String

Examples:

Dim result = SBToString(sb)

Example: Building a CSV row

Dim sb = GetStringBuilder()
For i = 0 To RowCount - 1
  If i > 0 Then SBAppend(sb, ",")
  SBAppend(sb, GetRowColumn(data, i, "Value"))
Next
Dim csv = SBToString(sb)