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.

 

 

 

 

 

 

 

String.trim Function

Removes leading and trailing white-space characters from a String object.

Syntax

var trimmedStringVar = myString.trim();

Return Value

A copy of the string with all white-space characters removed from the start and end of the string.

Remarks

Use the trim function to remove leading and trailing white-space characters from the current String object. Examples of white-space characters are spaces and tabs.

Example

The following example shows how to use the trim function to remove leading and trailing white space from a String object.

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>Sample</title>
</head>
<body>
    <form id="form1" runat="server">
        <asp:ScriptManager runat="server" ID="ScriptManager1">
        </asp:ScriptManager>

        <script type="text/javascript">
            function runSample() 
            {
                var myString = "  A string  ";
                // Remove any leading and trailing white spaces.
                myString = myString.trim();
                alert("Test:" + myString + ".");
            } 

            // Displays: "Test:A string."
            runSample();
        </script>
    </form>
</body>
</html>