StringBuilder Class in VB.NET

In this article we will learn how to use StringBuilder Class in VB.NET.
  • 4262
 

In this article we will learn how to use StringBuilder Class in VB.NET.

StringBuilder Class

StringBuilder is a class which is used to handle strings. It Provides Some Standard Function like Append, Reverse, Remove and used for Mutable Strings. The StringBuilder class is defined in the System.Text namespace.

Properties

StringBuilder class has the following properties.

Length - Length property Represents length of the current StringBuilder object.

MaxCapacity - Gets the maximum capacity of this instance.

For example

Using StringBuilder class to append and replace function.

Imports System.Text
Module Module1
    Sub Main()
        Dim builder As New StringBuilder
        builder.Append("Rohatash")
        builder.Append("Kumar")
        Dim s As String = builder.ToString
        Console.WriteLine("This defines the append function:=" & s)
        builder.Replace("ha", "na")
        Dim m As String = builder.ToString
        Console.WriteLine("This defines the replace function:=" & m)
        Console.WriteLine("Length of string is:" + builder.Length.ToString())
    End Sub
End Module

 OUTPUT

c1.gif
 

Figure 1.

Categories

More Articles

© 2020 DotNetHeaven. All rights reserved.