RTrim in jQuery
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?
Solution 1:
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
Solution 2:
Just use the javascript replace to change the last string into nothing:
string1.replace(/~+$/g,"");