ARTICLE

How to Concatenat Strings in VB.NET

Posted by Manish Tewatia Articles | Visual Basic Language July 25, 2010
In this article we use a new class StringBuilder to perform string concatenation.
 
Reader Level:

We can concatenate string Vb.Net by using '&' operator but there is a drawback of this procedure of concatenation that on every concatenation, a string variable was created and the old one was destroyed. So, Vb.Net provided a new class called StringBuilder to resolving the old problem. The StringBuilder dynamically allocates the memory block to the same object. It resides in the system.text namespace.

Here is the Example of using StringBuilder class

    Imports System.Text
    Module Module1
        Sub Main()
            Dim concatenation As New StringBuilder()
            concatenation.Append(
"Manish ")
            concatenation.Append(
"is student ")
            concatenation.Append(
"of ")
            concatenation.Append(
"NIIT.")
            Dim myString As New String(concatenation.ToString())
            Console.WriteLine(concatenation)
            Console.ReadLine()
        End Sub
    End
Module

OUTPUT

1.gif

CONCLUSION

So, in this article you see two separate objects, first is StringBuilder which take care of memory management and the another is .toString() which is responsible for the result output production.

Login to add your contents and source code to this article
share this article :
post comment
 
Become a Sponsor
PREMIUM SPONSORS
  • The leading .NET charting control now features PDF, Flash and Silverlight export, visualization of large datasets and more. Deliver true charting functionality to your BI, Scorecard, Presentation or Scientific apps. Download evaluation now.
    Get 2 Months Free of ASP.NET Hosting for Only $4.95/month! Receive FREE MS SQL and MySQL Databases Including ASP.NET 4/3.5, MVC 3.0, Silverlight 4, Windows 2008/IIS 7.0 Plus FREE IIS 7 Modules. Host UNLIMITED ASP.NET Web Sites - Click Here!
Become a Sponsor