Documentation for: ASP.NET Ajax Version 1.0

This documentation is for a previous version. For the current released version, see the ASP.NET Ajax documentation on MSDN.

 

 

 

 

 

 

 

Sys.StringBuilder Class

Provides a mechanism to concatenate strings.

Namespace: Sys

Inherits: None

Syntax

var stringBuilderVar = StringBuilder(string);

Constructors

StringBuilder Constructor

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

Members

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.

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.

JavaScript

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://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>