trimming - Removing only the last whitespace in string - Javascript -


this question has answer here:

how can remove last whitespace (if there any) user input? example:

var str = "this   "; 

how can remove last 1-4 whitespaces still keep first 2 whitespace (between this, , it)

question solved - lot!

using function this:

string.prototype.rtrim = function () {     return this.replace(/((\s*\s+)*)\s*/, "$1"); } 

call:

str.rtrim() 

addition if remove leading space:

string.prototype.ltrim = function () {     return this.replace(/\s*((\s+\s*)*)/, "$1"); } 

Popular posts from this blog

Php - Delimiter must not be alphanumeric or backslash -

c# - How to change the "Applies To" field under folder auditing options programatically (.NET) -

c++ - Ambiguity when using boost::assign::list_of to construct a std::vector -