Reader Level:

Modification in string using Stringbuilder class in

By Hirendra Sisodiya on Nov 09, 2012
This article shows that how to modify string using stringbuilder class in

String can be modified by using stringbuilder class. We can take an example for better understanding, suppose there are two string string11 and string2:

        Dim String1 As New StringBuilder("Hello")

        Dim String2 As New StringBuilder()

On above String1 is created with five characters 'Hello' and String is created as an empty string, we can modified these string dynamically such as we can append these string or add some string on we can say that this class can be used when we want to modify a string without creating a new object. On here String1 and String2 can be also called by dynamic strings or mutable strings.

String Builder class provides many methods and properties such as:



Appends information to the end of the current StringBuilder.


Replaces a format specifier passed in a string with formatted text.


Inserts a string or object into the specified index of the current StringBuilder.


Removes a specified number of characters from the current StringBuilder.


Replaces a specified character at a specified index.


Private Sub Example_StringBuilder()

        Dim String1 As New StringBuilder("beautiful")

        Dim String2 As New StringBuilder()



        String2 = String1.Append(" Picture")

        ' value of String2="beautiful Picture"


        String2 = String1.Remove(2, 4)

        ' value of String2="beful Picture"


        String2 = String1.Insert(2, "auti")

        ' value of String2="beautiful Picture"


        String2 = String1.Replace("beautiful", "Wonderful")

        ' value of String2="Wonderful Picture"

    End Sub


String2 ='beautiful Picture'
String2 ='beful Picture'
String2 ='beautiful Picture'
String2 ='Wonderful Picture'

Hirendra Sisodiya
Hirendra Sisodiya

My main area of experience has been application development. I have worked primarily in the domain of banking and financial services etc. My technological forte is Microsoft Technologies especially VB 6.0, Dot Net (Visua... Read more