왜 자바스크립트의 String에는 trim이 없는가!!왜 자바스크립트의 String에는 trim이 없는가!!

Posted at 2008. 12. 25. 17:12 | Posted in 프로그래밍 언어/Javascript
왜 없지-_-;

String에 trim 함수를 추가해 주자;

String.prototype.trim = function()
{
    return this.replace(/^\s+/, '').replace(/\s+$/, '');
}

앞의 replace가 left-trim이고 뒤의 replace가 right-trim이다.

white space로 시작하는 문자열이면 그 white space를 ""로 치환,

white space로 끝나는 문자열이면 그 white space를 "'로 치환.
//