함수구현


replaceAll

function replaceAll(str, searchStr, replaceStr) {

    while (str.indexOf(searchStr) != -1) {
        str = str.replace(searchStr, replaceStr);
    }
    return str;
}

 

■ trim()


  //-------------------------------------------------------------------------

  // 프로토타입에 정의하여 사용하기
  // 사용법 : 트림할문자변수.trim()
  //-------------------------------------------------------------------------
  String.prototype.trim = function() {
    return this.replace(/^\s\s*/,"").replace(/\s\s*$/,"");
  }


+ Recent posts