[go: up one dir, main page]

0% found this document useful (0 votes)
23 views1 page

Complete-Reference-Vb Net 29

Uploaded by

khalid
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
23 views1 page

Complete-Reference-Vb Net 29

Uploaded by

khalid
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

Capacity

The StringBuilder class is created similarly to the String object, as follows:

Dim MyStringBuilder As New StringBuilder("Hello Ariel!")

Naturally, you have access to this object's ToString method, so I won't go into it. The members of the
StringBuilder class are listed in Table 15−7.

Capacity

Once you have declared a variable of StringBuilder, it's easy to work with. This property ensures that the
capacity of this instance of StringBuilder is at least the specified value. To set the capacity in the declaration,
first initialize the object and pass in the capacity valuein this case 25as the second argument to the constructor
as follows:

Dim MyStringBuilder As New StringBuilder("Hello Ariel!", 85)

Meanwhile, the MaxCapacity property, as listed in Table 15−7, gets the maximum capacity of the object.

Append

The Append method can be used to add text or a collection of characters to the end of the object's collection
of characters. The following code example initializes a StringBuilder object to "To be or not to be" and then
appends some text to the end of the StringBuilder object. Space is allocated automatically as needed.

Dim MyStringBuilder As New StringBuilder_


("To be or not to be . . . ")
MyStringBuilder.Append("that is the question")
Console.WriteLine(MyStringBuilder)

Table 15−7: Members of the StringBuilder Class

Member Purpose
New Creates a new instance of the StringBuilder class
Capacity (p) Allocates the maximum number of characters that can be contained in the
memory allocated by the object
Chars (p) Retrieves or returns the character at the specified character position in the
object
Length (p) Retrieves or returns the length of the object's value
MaxCapacity (p) Retrieves the maximum capacity of the object
Append Appends characters onto the end of the String representation in the object
AppendFormat Works like Append but the StringBuilder object can take a formatted String,
as we discussed in the previous section. Each format specification is replaced
by the String representation of a corresponding object argument
EnsureCapacity Used to make sure that the capacity of the object you are referencing is at least
a specified value
Insert Inserts the collection of characters of a specified object into the referenced
object, at a specified character position
Remove

513

You might also like