StringBuilder - Optimum method for Concatenation

« View all ASP.net articles

March 20, 2007

The StringBuilder is a method to concatenate strings. It is much more efficient over using the "&" operator for concatenation. Using "&" destroys and creates a new string object every time causing for a much slower performance. The StringBuilder allocates a buffer memory for characters. See the StringBuilder in action in conjunction with a DataReader example.

To use the SrtingBuilder you declare a variable as a StringBuilder and use the append command for concatenation.
Dim htmlStr As New StringBuilder("")
htmlStr.Append("text")