반응형
1.function trim(str) {
2. return str.replace(/^\s\s*/, '').replace(/\s\s*$/, '');
3.}
4.String.prototype.trim = function() {
5. return this.replace(/^\s\s*/, '').replace(/\s\s*$/, '');
6.}
javascript에는 공백제거를 하는 trim함수가 없다 ;;
그래서 정규표현식을 사용하여 공백을 제거한다.

정규표현식
^ - 처음시작(beginning of line)
\s - 공백(whitespace character)
$ - 끝라인(end of line)

원글
http://junyong.tistory.com/31
반응형

+ Recent posts