Web Gadget SDK Web Gadget SDK
[Back to Web Gadget API Reference]
Web.StringBuilder Class
Provides an efficient approach to concatenating strings. Because strings in JavaScript are immutable, it is more efficient to use this class to build strings if you will be performing a lot of concatenating operations.
append Method
Appends the specified string to the StringBuilder object.
Syntax
strBldr.append(strParam)
Parameters
Parameter Description
strParam The string to be appended to the StringBuilder object.
Return Value
None
Example
The following example uses the append method in the Web.StringBuilder class to efficiently concatenate strings.
var strBldr = new Web.StringBuilder();
strBldr.append("This is a ");
strBldr.append("complete sentence.");
var strComplete = strBldr.toString();

// strComplete now equals to "This is a complete sentence."
appendLine Method
Appends the specified string and a carriage return to the StringBuilder object.
Syntax
strBldr.appendLine(strLineParam)
Parameters
Parameter Description
strLineParam The string to be appended to the StringBuilder object. A carriage return will also be appended at the end of this string.
Return Value
None
Example
The following example uses the appendLine method in the  Web.StringBuilder class to efficiently concatenate strings.
var strBldr = new Web.StringBuilder();
strBldr.appendLine("This is the first line.");
strBldr.append("This is the second line.");
var strComplete = strBldr.toString();

// strComplete now equals to "This is the first line.\r\nThis is the second line."
clear Method
Clears the string value contained in the StringBuilder object.
Syntax
strBldr.clear()
Parameters
None
Return Value
None
Example
The following example uses the clear method in the Web.StringBuilder class to clear the string contained in the StringBuilder object.
var strBldr = new Web.StringBuilder();
strBldr.appendLine("This is the first line.");
strBldr.append("This is the second line.");
var strComplete = strBldr.toString();
// strComplete now equals to "This is the first line.\r\nThis is the second line."

strBldr.clear();
var strCleared = strBldr.toString();
// strCleared now equals to ""
isEmpty Method
Checks to see if the string value contained in the StringBuilder object is empty.
Syntax
strBldr.isEmpty();
Parameters
None
Return Value
Boolean value indicating whether the string contained in the StringBuilder object is empty or not. True if the string is empty, false otherwise.
toString Method
Returns the string value contained in the StringBuilder object.
Syntax
strBldr.toString();
Parameters
None
Return Value
String value contained in the StringBuilder object.