ARTICLE

Modification in string using Stringbuilder class in VB.net

Posted by Hirendra Sisodiya Articles | Visual Basic 2010 February 07, 2011
this article shows that how to modify string using stringbuilder class in vb.net
 
Reader Level:

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 it.so 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:

Methods:

Append

Appends information to the end of the current StringBuilder.

AppendFormat

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

Insert

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

Remove

Removes a specified number of characters from the current StringBuilder.

Replace

Replaces a specified character at a specified index.

Example:

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

 Output:

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

Login to add your contents and source code to this article
share this article :
post comment
 
6 Months Free & No Setup Fees ASP.NET Hosting!
Become a Sponsor
PREMIUM SPONSORS
  • Finally – a virtual platform that delivers next-generation Windows Server 2008 Hyper-V virtualization technology from a managed hosting partner you can truly depend on. Visit www.maximumasp.com/max for a FREE 30 day trial. Hurry offer ends soon. Climb aboard the MaxV platform and take advantage of High Availability, Intelligent Monitoring, Recurrent Backups, and Scalability – with no hassle or hidden fees. As a managed hosting partner focused solely on Microsoft technologies since 2000, MaximumASP is uniquely qualified to provide the superior support that our business is built on. Unparalleled expertise with Microsoft technologies lead to working directly with Microsoft as first to offer IIS 7 and SQL 2008 betas in a hosted environment; partnering in the Go Live Program for Hyper-V; and product co-launches built on WS 2008 with Hyper-V technology.
    ceTE software specializes in components for dynamic PDF generation and manipulation. The DynamicPDF™ product line allows you to dynamically generate PDF documents, merge PDF documents and new content to existing PDF documents from within your applications.
Nevron Diagram
Become a Sponsor