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

How to calculate SNR of signals in MATLAB? -

c# - Attempting to upload to FTP: System.Net.WebException: System error -

ios - UISlider customization: how to properly add shadow to custom knob image -