String.trimEnd Function

Removes trailing white-space characters from a String object.

var trimmedStringVar = myString.trimEnd();

Return Value

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

Remarks

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

Example

The following code example demonstrates how to use the trimEnd function to remove trailing white space from a String object.

<!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>Untitled Page</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 specified suffix as 
            // the last non white-space characters regardless of case.
            function verifyStringSuffix(myString, suffix) 
            {
                // Remove any trailing white spaces.
                myString = myString.trimEnd();

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

                // Determine if the string ends with the specified suffix.
                var isTxt = myString.endsWith(suffix.toString());

                if (isTxt === true)
                {
                    alert("The string \"" + myString + "\" ends with \"" + suffix + "\""); 
                }
                else
                {
                   alert("The string \"" + myString + "\" does not end with \"" + suffix + "\""); 
                }
            }

            verifyStringSuffix("some_file.TXT  ", ".txt");

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


See Also

Reference

String.trimStart Function

Other Resources

Language Reference