엄청 간단합니다.

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, "");
}

str = "   1234567890   ";
ltrim = str.ltrim();
rtrim = str.rtrim();
trim = str.trim();

result = "<pre>orignal = \"" + str + "\"\n";
result += "ltrim length = " + ltrim.length + ", string = \"" + ltrim + "\n";
result += "rtrim length = " + rtrim.length + ", string = \"" + rtrim + "\n";
result += "trim length = " + trim.length + ", string = \"" + trim + "\n";

document.write(result);

크리에이티브 커먼즈 라이선스
Creative Commons License
Posted by Johan Kim hiphapis

TRACKBACK http://hiphapis.net/trackback/67 관련글 쓰기

  1. 정귯ㄱ  삭제

    2009/02/20 23:48TRACKBACK FROM I think about...

댓글을 달아 주세요

  1. 감사합니다

    2011/12/20 15:02 [ ADDR : EDIT/ DEL : REPLY ]