String.trimEnd Function
Removes trailing white-space characters from a String object.
var trimmedStringVar = myString.trimEnd();
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" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://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>
Show: