str_pad 함수 구현 > JS

본문 바로가기




WEBDEV


사이트 내 전체검색


str_pad 함수 구현 > JS

str_pad 함수 구현

페이지 정보

작성자 최고관리자 댓글 0건 조회 2,470회 작성일 18-02-07 00:31

본문

function strPad(input, pad_length, pad_string, pad_type){
 var output = input.toString();
 if (pad_string === undefined) { pad_string = ' '; }
 if (pad_type === undefined) { pad_type = 'STR_PAD_RIGHT'; }
 if (pad_type == 'STR_PAD_RIGHT') {
  while (output.length < pad_length) {
   output = output + pad_string;
  }
 } else if (pad_type == 'STR_PAD_LEFT') {
  while (output.length < pad_length) {
   output = pad_string + output;
  }
 } else if (pad_type == 'STR_PAD_BOTH') {
  var j = 0;
  while (output.length < pad_length) {
   if (j % 2) {
    output = output + pad_string;
   } else {
    output = pad_string + output;
   }
   j++;
  }
 }
 return output;
}

댓글목록

등록된 댓글이 없습니다.



개인정보처리방침
서비스이용약관
모바일버전
그누보드5
Copyright © 소유하신 도메인. All rights reserved.