trimming - Removing only the last whitespace in string - Javascript -
this question has answer here:
- trim string in javascript? 24 answers
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"); }