A string object is immutable (once it has been created, it cannot be
changed). Contrary to popular belief,
Dim szTest as String
szTest = "Test1"
' This causes szTest to be assigned to a new object rather than "123"
getting bolted onto the back of it
szTest = szTest & "123"
Because a new object is created with every assignment, there is a slight
overhead when doing this repeatedly.
The string builder class provides a more efficient way to repeatedly add
bits on to a string. You provide it with an initial capacity (it grows
automatically, but will degrade performance if it grows too often). You can
add more bits of strings to it without the overhead of creating a new
object.
When you are finished building the string, use the ToSting method of the
StringBuilder to turn it into an ordinary string.
The performance difference will be too small to measure if you're only doing
a few concatenations, but if you're in a loop, building a big string (e.g.
HTML code for a web page) then StringBuilder has a definite advantage.
Hope this helps,
Trev.
"John" <jo**@nospam.infovis.co.uk> wrote in message
news:#3**************@TK2MSFTNGP12.phx.gbl...
Hi
What are the advantages of a stringbuilder compared to a string?
Thanks
Regards