JavaScript 공백 제거 방법 집합
                                            
 7030 단어  공백 을 없애다
                    
 
String.prototype.trim = function () { 
return this .replace(/^\s\s*/, '' ).replace(/\s\s*$/, '' ); 
} 
 
String.prototype.trim = function () { 
return this .replace(/^\s+/, '' ).replace(/\s+$/, '' ); 
} 
 
String.prototype.trim = function () { 
return this .substring(Math.max( this .search(/\S/), 0), this .search(/\S\s*$/) + 1); 
} 
 
String.prototype.trim = function () { 
return this .replace(/^\s+|\s+$/g, '' ); 
} 
 
String.prototype.trim = function () { 
var str = this ; 
str = str.match(/\S+(?:\s+\S+)*/); 
return str ? str[0] : '' ; 
} 
 
String.prototype.trim = function () { 
return this .replace(/^\s*(\S*(\s+\S+)*)\s*$/, '$1' ); 
} 
 
String.prototype.trim = function () { 
return this .replace(/^\s*(\S*(?:\s+\S+)*)\s*$/, '$1' ); 
} 
 
String.prototype.trim = function () { 
return this .replace(/^\s*((?:[\S\s]*\S)?)\s*$/, '$1' ); 
} 
 
String.prototype.trim = function () { 
return this .replace(/^\s*([\S\s]*?)\s*$/, '$1' ); 
} 
 
String.prototype.trim = function () { 
var str = this , 
whitespace = ' 
\r\t\f\x0b\xa0\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200a\u200b\u2028\u2029\u3000' ; 
for ( var i = 0,len = str.length; i < len; i++) { 
if (whitespace.indexOf(str.charAt(i)) === -1) { 
str = str.substring(i); 
break ; 
} 
} 
for (i = str.length - 1; i >= 0; i--) { 
if (whitespace.indexOf(str.charAt(i)) === -1) { 
str = str.substring(0, i + 1); 
break ; 
} 
} 
return whitespace.indexOf(str.charAt(0)) === -1 ? str : '' ; 
} 
 
String.prototype.trim = function () { 
var str = this , 
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; 
} 
 
String.prototype.trim = function () { 
var str = this , 
str = str.replace(/^\s\s*/, '' ), 
ws = /\s/, 
i = str.length; 
while (ws.test(str.charAt(--i))); 
return str.slice(0, i + 1); 
} 
 
//String.prototype   
//    ,  :str.ReplaceAll([/a/g,/b/g,/c/g],["aaa","bbb","ccc"]) 
String.prototype.ReplaceAll=function (A,B) { 
var C=this; 
for(var i=0;i<A.length;i++) { 
C=C.replace(A[i],B[i]); 
}; 
return C; 
}; 
//             
String.prototype.Trim=function () { 
return this.replace(/(^[\t
\r]*)|([\t
\r]*$)/g,''); 
}; 
//             
String.prototype.LTrim=function () { 
return this.replace(/^[\t
\r]/g,''); 
}; 
//             
String.prototype.RTrim=function () { 
return this.replace(/[\t
\r]*$/g,''); 
}; 
//        ,     2  
String.prototype.ChineseLength=function() 
{ 
return this.replace(/[^\x00-\xff]/g,"**").length; 
}; 
//                  
String.prototype.EndsWith=function (A,B) { 
var C=this.length; 
var D=A.length; 
if(D>C)return false; 
if(B) { 
var E=new RegExp(A+'$','i'); 
return E.test(this); 
}else return (D==0||this.substr(C-D,D)==A); 
}; 
//                  
String.prototype.StartsWith = function(str) 
{ 
return this.substr(0, str.length) == str; 
}; 
//               
String.prototype.Remove=function (A,B) { 
var s=''; 
if(A>0)s=this.substring(0,A); 
if(A+B<this.length)s+=this.substring(A+B,this.length); 
return s; 
};