List of utility methods to do String Trim
trim()String.prototype.trim = function() { return this.replace(/^\s+/g,"").replace(/\s+$/g,""); }; | |
trim(c)String.prototype.trim = function (c) { if (c) { var r = new RegExp('(^' + c + ')|(' + c + '$)', 'g'); return this.replace(r, ''); } else { return this.replace(/^\s+|\s+$/g,''); }; String.prototype.capitalize = function() { ... | |
trim(c, t)String.prototype.trim = function(c, t){ return c = "[" + (c == undefined ? " " : c.replace(/([\^\]\\-])/g, "\\\$1")) + "]+", this.replace(new RegExp((t != 2 ? "^" : "") + c + (t != 1 ? "|" + c + "$" : ""), "g"), ""); }; | |
trim(c, t)String.prototype.trim = function(c, t){ return c = "[" + (c == undefined ? " " : c.replace(/([\^\]\\-])/g, "\\\$1")) + "]+", this.replace(new RegExp((t != 2 ? "^" : "") + c + (t != 1 ? "|" + c + "$" : ""), "g"), ""); }; | |
trim(ch)String.prototype.trim = function(ch) { var r = new RegExp("^{0}+|{0}+$".format(ch || "\\s"), "g"); return this.replace(r, ""); }; | |
trim(character)String.prototype.trim = function (character) { return this.trimLeft(character).trimRight(character); }; | |
trim(charlist)'use strict'; String.prototype.trim = function (charlist) { return this.ltrim(charlist).rtrim(charlist); }; | |
trim(chars)String.prototype.trim = function(chars) { return this.replace(new RegExp('^[' + (chars || '\\s') + ']+|[' + (chars || '\\s') + ']+$', 'g'), ''); }; | |
trim(fag='default')String.prototype.trim = function (fag='default'){ const preg_arr = {'default':/(^\s*)|(\s*$)/,'left':/(^\s*)/,'right':/(\s*$)/}; switch(fag){ case 'left': return this.replace(preg_arr.left,''); break; case 'right': return this.replace(preg_arr.right,''); break; ... | |
trim(str)String.prototype.trim = function(str) { str = str.replace(/^\s+/,''); for( var i = str.length - 1 ; i >= 0 ; i--) { if(/\S/.test(str.charAt(i))) { str = str.substring(0,i+1); break; return str; ... |