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.trimStart Function

Removes leading white-space characters from a String object.

Syntax

var trimmedStringVar = myString.trimStart();

Return Value

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

Remarks

Use the trimStart function to remove leading 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 trimStart function to remove leading white space from a current 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">
            // Determines if a string has a specific prefix as 
            // the first non white-space characters in a string.
            function verifyString(myString, prefix) 
            {
                // Remove any white space at the left of the string.
                myString = myString.trimStart();

                // Set to lower case.
                myString = myString.toLowerCase();

                // Determine if the string starts with the specified prefix.
                var hasPrefix = myString.startsWith(prefix.toString());
                if (hasPrefix === true)
                {
                    alert("The string \"" + myString + "\" starts with \"" + prefix + "\""); 
                }
                else
                {
                   alert("The string \"" + myString + " does not start with \"" + prefix + "\""); 
                }
             }

            // Displays: The string "green_blue_red" starts with "green"
            verifyString("  GREEN_BLUE_RED  ", "green");

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