본문 바로가기
프로그램/Javascript

trim(), ltrim(), rtrim()

by 로드러너 2014. 3. 5.
336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.

Example

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

 

     var str = “  123 ABC  ”;

 

     str.trim()     // “123 ABC”

     str.ltrim()     // “123 ABC  ”

     str.rtrim()     // “  123 ABC”

 

'프로그램 > Javascript' 카테고리의 다른 글

Locale 가져오기  (0) 2014.03.11
Table에 동적으로 TR, TD 추가하기  (0) 2014.03.07
function(){}();  (0) 2014.03.04
Object 객체  (0) 2014.03.03
String.replace()  (0) 2014.03.01