Friday, September 9, 2011

Using StringBuilder

StringBuilder is very useful if you are working on string with a lot of concatenation. String has its own limitation and is very slow when you do a lot of string manipulations.

Here is an example of using StringBuilder:

Import System.Text
Imports System.Text

Example using Append method.
Dim dString As New StringBuilder
dString.Append("This is a string. ")
dString.Append("This is another string.")

The output of this will be: "This is a string. This is another string."

Example using AppendFormat method
Dim dString As New StringBuilder
Dim dString1 As String = "Append"
Dim dString2 As String = "Format"
dString.AppendFormat("This is a string using {0}{1},", dString1, dString2)

No comments:

Post a Comment