javascript trim

script 2008. 8. 27. 22:17
function trim(str) {
return str.replace(/^\s\s*/, '').replace(/\s\s*$/, '');
}

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

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

'script' 카테고리의 다른 글

xhtml dtd  (0) 2008.10.04
offsetTop / offsetLeft  (0) 2008.10.01
[Link] 고급 JavaScript 작성하기  (0) 2008.09.25
window.open() 팝업  (0) 2008.09.23
SyntaxHighlighter(Code google) Supported languages  (0) 2008.09.11
textarea byte check  (0) 2008.09.10
jQuery API  (2) 2008.08.11
window.onload 실행 순서(IE)  (0) 2008.07.30
firstChild  (0) 2008.06.02
javascript packer  (0) 2008.04.29
: