Partager via


Sys.StringBuilder Class

Provides a mechanism to concatenate strings.

Namespace: Sys

Inherits: None

var stringBuilderVar = StringBuilder(string);

Constructors

Members

Remarks

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

Example

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" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="https://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
    <title>Samples</title>
</head>
<body>
    <form id="form1" runat="server">
       <asp:ScriptManager runat="server" ID="ScriptManager1">
       </asp:ScriptManager>

       <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);
                sb.append(titleTagEnd);
                sb.append(title);
                sb.append(titleTagEnd);
                sb.append(headTagEnd);
                // Displays: "The result: <head><title>A Title</title></head>"
                alert("The result" + sb.toString()); 
            }

            var title = "A Title";
            buildAString(title);

        </script>
    </form>
</body>
</html>

See Also

Reference

new Operator

Other Resources

Language Reference