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.


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


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" "">
<html xmlns="" >
<head id="Head1" runat="server">
    <title>Untitled Page</title>
    <form id="form1" runat="server">
        <asp:ScriptManager runat="server" ID="ScriptManager1">
        <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 + "\""); 
                   alert("The string \"" + myString + "\" does not end with \"" + suffix + "\""); 

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


See Also


String.trimStart Function

Other Resources

Language Reference