Usually when using StringBuilder, we call Append in a loop—here we have 2 For-loops. We call Append 3 times in each loop.
Imports System.Text
Module Module1
Sub Main()
Const s As String =
"(s)"
' Version 1: call Append in loop.
Dim builder = New StringBuilder()
For i = 0 To 2
builder.Append(
"Start")
builder.Append(s)
builder.Append(
"End")
Next
' Version 2: call Append in loop in same statement.
Dim builder2 = New StringBuilder()
For i = 0 To 2
builder2.Append(
"Start").Append( s).Append(
"End")
Next
Console.WriteLine(
"BUILDER: {0}", builder)
Console.WriteLine(
"BUILDER 2: {0}", builder2)
End Sub
End Module
BUILDER: Start(s)EndStart(s)EndStart(s)End
BUILDER 2: Start(s)EndStart(s)EndStart(s)End