엄청 간단합니다.
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, "");
}
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);
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);
'웹[기술|표준|접근] > 작은 팁' 카테고리의 다른 글
| EditPlus 에서 monaco(mac 기본 폰트)사용하기. (XP에서 안티알리아싱(Anti-Aliasing 설정) (3) | 2007/10/01 |
|---|---|
| [CSS] IE6 에서 CSS만으로(핵안쓰고) position:fixed 하기 (2) | 2007/08/31 |
| [JS] 정규식을 이용하여 ltrim, rtrim, trim 구현하기 (1) | 2007/08/31 |
| [JS] timestamp 를 date 형식으로 보여주기(as like php date()) (0) | 2007/08/08 |
| [font series 2]폰트사이즈만 상대적으로 하면 된다? (2) | 2007/08/01 |
| [font series 1]웹에서 Font Size 문제.. (2) | 2007/08/01 |
댓글을 달아 주세요
감사합니다
2011/12/20 15:02 [ ADDR : EDIT/ DEL : REPLY ]