trim3 trim() function trim11 (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; } 2014. 3. 19. trim(), ltrim(), rtrim() Example String.prototype.trim = function(){ return this.replace(/(^\s*)|(\s*$)/g, “”);} String.prototype.ltrim = function(){ return this.replace(/(^\s*)/g, “”);} String.prototype.rtrim = function(){ return this.replace(/(\s*$)/g);} var str = “ 123 ABC ”; str.trim() // “123 ABC” str.ltrim() // “123 ABC ” str.rtrim() // “ 123 ABC” 2014. 3. 5. 압뒤 공백 제거 var temp = " Test ";temp.replace(/(^\s*)|(\s*$)/gi, ""); 2014. 1. 23. 이전 1 다음