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? -

java - How to create Table using Apache PDFBox -

mpi - Why is MPI_Bsend not returning error even when the buffer is insufficient to accommodate all the messages -