I am having a problem with jQuery's trim. I have a string such at in jQuery:
var string1; string1 = "one~two~";
How do I trim the trailing tilde?
The rtrim() function removes whitespace or other predefined characters from the right side of a string. Related functions: ltrim() - Removes whitespace or other predefined characters from the left side of a string.
The $. trim() function removes all newlines, spaces (including non-breaking spaces), and tabs from the beginning and end of the supplied string. If these whitespace characters occur in the middle of the string, they are preserved.
jQuery trim() method The trim() method is used to remove the space, tabs, and all line breaks from the starting and end of the specified string. This method does not remove these characters if these whitespace characters are in the middle of the string. The commonly used syntax of using this method is given as follows.
The .trim()
method of jQuery refers to whitespace ..
Description: Remove the whitespace from the beginning and end of a string.
You need
string1.replace(/~+$/,'');
This will remove all trailing ~
.
So one~two~~~~~
would also become one~two
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With