Sys.StringBuilder Class

Provides a mechanism to concatenate strings.

Namespace: Sys

Inherits: None

var stringBuilderVar = StringBuilder(string);

Sys.StringBuilder Constructor

Creates a new instance of StringBuilder and optionally accepts initial text to concatenate.

Sys.StringBuilder append Method

Appends a string to the end of the StringBuilder instance.

Sys.StringBuilder appendLine Method

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

Sys.StringBuilder clear Method

Clears the contents of the StringBuilder instance.

Sys.StringBuilder isEmpty Method

Determines whether the StringBuilder instance has any content.

Sys.StringBuilder toString Method

Creates a string from the contents of a StringBuilder instance.

The StringBuilder class represents a mutable string of characters and provides a mechanism to concatenate a sequence of strings.

The following example shows how to create a new StringBuilder instance and call the append method to add a line of text. The code then calls the appendLine method to add a string with a line terminator at the end of the string. Finally, the code calls the toString method, passing a "|" character as a delimiter to insert between the elements of the string returned by StringBuilder.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">
<html xmlns="" >
<head id="Head1" runat="server">
    <form id="form1" runat="server">
       <asp:ScriptManager runat="server" ID="ScriptManager1">

       <script type="text/javascript">
            function buildAString(title){
                var headTagStart = "<head>";
                var headTagEnd = "</head>";
                var titleTagStart = "<title>";
                var titleTagEnd = "</title>";

                var sb = new Sys.StringBuilder(this._headTagStart);
                // Displays: "The result: <head><title>A Title</title></head>"
                alert("The result" + sb.toString()); 

            var title = "A Title";