CopyCode The Code is as follows: // initializes a new instance of the stringbuilder class
// And appends the given value if supplied
Function stringbuilder (value)
{
This. Strings = new array ("");
This. append (value );
}
// Appends the given value to the end of this instance.
Stringbuilder. Prototype. append = function (value)
{
If (value)
{
This. Strings. Push (value );
}
}
// Clears the string buffer
Stringbuilder. Prototype. Clear = function ()
{
This. Strings. Length = 1;
}
// Converts this instance to a string.
Stringbuilder. Prototype. tostring = function ()
{
Return this. Strings. Join ("");
}
The code looks simple and straightforward. It is actually implemented using array, push, join, etc. The following describes how to use this classCopy codeThe Code is as follows: // create a stringbuilder
VaR sb = new stringbuilder ();
// Append some text
SB. append ("some of those preparing for international ");
SB. append ("exams such as the TOEFL ");
SB. append ("need extra practice for the listening section ");
// Get the full string value
VaR S = sb. tostring ();
Alert (s );
It is very simple and does not require much explanation. If you use stringbuilder in. net, you will also know how to use it.