달력

09

« 2010/09 »

  •  
  •  
  •  
  • 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
  •  
  •  
엄청 간단합니다.

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 기다림