블로그 이미지
암초보

calendar

1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31

Notice

Tag

05-02 18:39
2009. 9. 28. 20:23 프로그래밍/JavaScript

var str = "';

str.replace(/(^\s*)|(\s*$)/g,"");//공백제거됨

 

 /* =================================================================
  앞/뒤 공백 제거
 ================================================================= */

 String.prototype.trim = function() {
  return this.replace(/\s/g, "");
 }

 

 /* =================================================================
  앞 공백 제거
 ================================================================= */

 String.prototype.ltrim = function() {

  var i, j = 0;
  var objstr

  for (i = 0; i < this.length; i++) {

   if (this.charAt(i) == ' ') j = j + 1;
   else break;
  }

  return this.substr(j, this.length - j + 1) 
 }

 /* =================================================================
  뒤 공백 제거
 ================================================================= */

 String.prototype.rtrim = function() {

  var i, j = 0;

  for (i = this.length - 1; i >= 0; i--) {

   if (this.charAt(i) == ' ') j = j + 1;
   else break;
  }

  return this.substr(0, this.length - j);
 }

'프로그래밍 > JavaScript' 카테고리의 다른 글

날짜 계산관련 스크립트  (0) 2009.09.30
유용한팁.  (0) 2009.09.28
window.open() 함수 사용시 주소표시줄 설정.  (0) 2009.08.29
LiteBox2  (0) 2009.08.23
getElementById 할 때..  (0) 2009.07.20
posted by 암초보