Ajax StringBuilder for Javascript

String builder is used to concatenate string. the mechanism is created in such a way that the memory is not wasted for concatenating a sequence of strings. adding a string using the '+' operator creates a new instance of the string variable each time we add. String builder does the same job with a single instance. this reduces the memory and increses performance.

StringBuilder belongs to namespace Sys.
it can be instantiated like this
var sb = new Sys.StringBuilder(string);
Methods of StringBuilder Class

append Method
Appends a string to the end of the StringBuilder instance.

appendLine Method
Appends a new string with a line terminator to the end of the StringBuilder instance.

clear Method
Clears the contents of the StringBuilder instance.

isEmpty Method
Determines whether the StringBuilder instance has any content.

toString Method
Creates a string from the contents of a StringBuilder instance.

var sb = new Sys.StringBuilder("this");
sb.append("string ");
sb.append("is ");
sb.append("build by ");
sb.append("String Builder class");
// Displays: "The result string : this string is build by String BUilder class"
alert("The result" + sb.toString());

No comments:

Post a Comment