Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

RTrim in jQuery

Tags:

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?

like image 753
Nate Pet Avatar asked Jan 09 '12 16:01

Nate Pet


People also ask

What is use of Rtrim?

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.

How do I remove spaces between words in jQuery?

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.

What is meant by trim in jQuery?

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.


1 Answers

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

like image 112
Gabriele Petrioli Avatar answered Sep 22 '22 23:09

Gabriele Petrioli