|
|
|
You can think of a StringBuilder object as a buffer that can contain a string with the ability to grow from zero characters to the buffer's current capacity. Until you exceed that capacity, the string is assembled in the buffer and no object is allocated or released. If the string becomes longer than the current capacity, the StringBuilder object transparently creates a larger buffer. The default buffer initially contains 16 characters, but you can assign a different capacity in the StringBuilder's constructor or by assigning a value to the Capacity property: |
You can process the string held in the StringBuilder object with several methods, most of which have same name as and work similarly to methods exposed by the String class-for example, the Insert, Remove, and Replace methods. The most common way to build a string inside a StringBuilder object is by means of its Append method, which takes an argument of any type and appends it to the current internal string: |
Because a StringBuilder doesn't allocate memory (or does it only when the internal buffer isn't long enough for the string being assign), it is much faster. For example, the code above is 100-150 faster than a similar loop based on the standard String class.
|
|
|
|
Submitted By :
Nayan Patel
(Member Since : 5/26/2004 12:23:06 PM)
|
|
|
Job Description :
He is the moderator of this site and currently working as an independent consultant. He works with VB.net/ASP.net, SQL Server and other MS technologies. He is MCSD.net, MCDBA and MCSE. In his free time he likes to watch funny movies and doing oil painting. |
View all (893) submissions by this author
(Birth Date : 7/14/1981 ) |
|
|