복스리

직접만든 자바스크립트 Trim 함수입니다.

vbscript에서는 Trim 기능이 있는데 javascript에서는 Trim기능이 없어서..고민하다가. 한번 만들어봤습니다.
함수 사용법은 vbscript과 같구요
 
함수명은 trim , rtrim, ltrim 3개 입니다.. 작업하시면서 필요하실껍니다.
 
<HTML>
<HEAD>
<TITLE> 자바스크립드 완벽 Trim 함수 </TITLE>
<script language="javascript">
function ltrim(value)
{
  var LeftTrimValue = "";
  var i=0;
  if( value == "" )
        return "";
  strLen = value.length;
  while(i<strLen)
  {
    if(value.charAt(i) != " ") break;
    i++;
  }
  for(s=i;s<strLen;s++)
  {
    LeftTrimValue = LeftTrimValue + value.charAt(s);
  }
  return LeftTrimValue;
}
function rtrim(value)
{
  var RightTrimValue = "";
  if( value == "" )
        return "";
  strLen = value.length;
  --strLen;
  while( 0 <= strLen)
  {
    if(value.charAt(strLen) != " ") break;
    --strLen;
  }
  for(s=0;s<=strLen;s++)
  {
    RightTrimValue = RightTrimValue + value.charAt(s);
  }
  return RightTrimValue;
}
function trim(value)
{
  return rtrim(ltrim(value));
}
function test()
{
  switch(eval(form.sel.value))
  {
    case 1 :  alert("\"" + trim(form.ok.value)  + "\"" ); break;
    case 2 :  alert("\"" + rtrim(form.ok.value) + "\"" ); break;
    case 3 :  alert("\"" + ltrim(form.ok.value) + "\"" ); break;
  }
}
</script>
</HEAD>
<body>
<form name="form">
  <select name="sel">
    <option value="1">Trim</option>
    <option value="2">rTrim</option>
    <option value="3">lTrim</option>
  </select>
  <input type="text" name="ok" >
  <input type="button" value="확인" onclick="test()"><br>
</form>
</BODY>
</HTML>
 
긁어다가 textbox에 글 넣구 스페이스 넣구 한번 동작해보세요
 
[이 게시물은 관리자님에 의해 2011-10-31 16:57:14 JavaScript에서 이동 됨]
|

댓글 1개

속도빠릅니다.
댓글을 작성하시려면 로그인이 필요합니다. 로그인

프로그램

+
제목 글쓴이 날짜 조회
18년 전 조회 2,224
18년 전 조회 2,529
18년 전 조회 1,771
18년 전 조회 2,100
18년 전 조회 1,989
18년 전 조회 2,507
18년 전 조회 1,925
18년 전 조회 1,718
18년 전 조회 1,747
18년 전 조회 1,723
18년 전 조회 2,756
18년 전 조회 1,548
18년 전 조회 5,665
18년 전 조회 2,395
18년 전 조회 1,663
18년 전 조회 4,708
18년 전 조회 2,053
18년 전 조회 4,841
18년 전 조회 3,187
18년 전 조회 2,132
18년 전 조회 1,825
18년 전 조회 2,096
18년 전 조회 1,721
18년 전 조회 1,836
18년 전 조회 1,835
18년 전 조회 2,476
18년 전 조회 3,496
18년 전 조회 5,968
18년 전 조회 3,860
18년 전 조회 3,055
18년 전 조회 2,130
18년 전 조회 2,401
18년 전 조회 2,182
18년 전 조회 2,303
18년 전 조회 2,400
18년 전 조회 2,839
18년 전 조회 2,534
18년 전 조회 1,988
18년 전 조회 3,123
18년 전 조회 3,585
18년 전 조회 3,832
18년 전 조회 3,333
18년 전 조회 3,376
18년 전 조회 2,560
18년 전 조회 2,462
18년 전 조회 2,449
18년 전 조회 2,318
18년 전 조회 2,553
18년 전 조회 3,850
18년 전 조회 3,651
18년 전 조회 2,080
18년 전 조회 2,018
18년 전 조회 1,552
18년 전 조회 3,885
18년 전 조회 5,889
18년 전 조회 6,985
18년 전 조회 2,463
18년 전 조회 2,710
18년 전 조회 4,166
18년 전 조회 2,172
18년 전 조회 3,617
18년 전 조회 2,873
18년 전 조회 2,730
18년 전 조회 2,200
18년 전 조회 2,463
18년 전 조회 2,592
18년 전 조회 3,087
18년 전 조회 3,732
18년 전 조회 3,271
18년 전 조회 2,778
18년 전 조회 2,270
18년 전 조회 2,940
18년 전 조회 3,030
18년 전 조회 2,540
18년 전 조회 2,296
18년 전 조회 3,329
18년 전 조회 4,849
18년 전 조회 5,068
18년 전 조회 2,291
18년 전 조회 2,186
18년 전 조회 4,995
18년 전 조회 8,958
18년 전 조회 2,044
18년 전 조회 4,921
18년 전 조회 4,361
18년 전 조회 2,604
18년 전 조회 4,958
18년 전 조회 2,786
18년 전 조회 3,666
19년 전 조회 2,619
19년 전 조회 3,430
19년 전 조회 1,943
19년 전 조회 5,373
19년 전 조회 1,691
19년 전 조회 6,049
19년 전 조회 2,869
19년 전 조회 6,036
19년 전 조회 6,831
19년 전 조회 3,721
19년 전 조회 2,203
🐛 버그신고