Copy Code code 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 is instance to a String.
StringBuilder.prototype.toString = function ()
{
Return This.strings.join ("");
}
The code looks simple and straightforward. is actually implemented with Array,push,join, and the following is how to use the class
Copy Code code 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);
Very simple, do not need too much description. If you're in. NET with StringBuilder, you will also know how to use it here.