Visual Basic - Save Time And Improve Efficiency With The String Builder Object (VB .NET)
If you have intensive concatenation operations, you should consider using the StringBuilder object instead of just a concatenating the strings. The StringBuilder object is more efficient because it allows you to work directly with the string instead of building, destroying, and re-building it, which is what happens with regular string concatenations. However, it also saves you a few keystrokes because you won't have to assign a new value to the string. Take a look at the following code snippet:
- Dim strName1 As String = "Visual"
- strName1 = strName1 & "Basic"
- Dim strName2 As System.Text.StringBuilder = New System.Text.StringBuilder
Obviously, this isn't a particularly sexy example, but for concatenation inside lengthy loops and other such intensive scenarios, the StringBuilder can be up to 50 times faster than concatenation.