StringBuilder.Capacity Property gets or sets the maximum number of characters that can be contained
Imports System.Text
Class Sample
Public Shared Sub Main()
Dim sb1 As New StringBuilder("abc")
Dim sb2 As New StringBuilder("abc", 16)
Console.WriteLine("{0}, {1}", sb1.Length, sb1.Capacity)
Console.WriteLine("{0}, {1}", sb2.Length, sb2.Capacity)
Console.WriteLine("{0}, {1}", sb1.ToString(), sb2.ToString())
Console.WriteLine(sb1.Equals(sb2))
sb1.EnsureCapacity(50)
Console.WriteLine("{0}, {1}", sb1.Length, sb1.Capacity)
Console.WriteLine("{0}, {1}", sb2.Length, sb2.Capacity)
Console.WriteLine("{0}, {1}", sb1.ToString(), sb2.ToString())
Console.WriteLine(sb1.Equals(sb2))
sb1.Length = 0
sb2.Capacity = 51
Console.WriteLine("{0}, {1}", sb1.Length, sb1.Capacity)
Console.WriteLine("{0}, {1}", sb2.Length, sb2.Capacity)
Console.WriteLine("{0}, {1}", sb1.ToString(), sb2.ToString())
Console.WriteLine(sb1.Equals(sb2))
End Sub
End Class
Related examples in the same category