복스리

직접만든 자바스크립트 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,226
18년 전 조회 2,529
18년 전 조회 1,774
18년 전 조회 2,102
18년 전 조회 1,991
18년 전 조회 2,507
18년 전 조회 1,927
18년 전 조회 1,720
18년 전 조회 1,748
18년 전 조회 1,726
18년 전 조회 2,757
18년 전 조회 1,549
18년 전 조회 5,667
18년 전 조회 2,397
18년 전 조회 1,665
18년 전 조회 4,709
18년 전 조회 2,055
18년 전 조회 4,842
18년 전 조회 3,189
18년 전 조회 2,133
18년 전 조회 1,826
18년 전 조회 2,099
18년 전 조회 1,722
18년 전 조회 1,837
18년 전 조회 1,837
18년 전 조회 2,477
18년 전 조회 3,498
18년 전 조회 5,969
18년 전 조회 3,861
18년 전 조회 3,056
18년 전 조회 2,132
18년 전 조회 2,404
18년 전 조회 2,184
18년 전 조회 2,304
18년 전 조회 2,403
18년 전 조회 2,841
18년 전 조회 2,535
18년 전 조회 1,992
18년 전 조회 3,125
18년 전 조회 3,587
18년 전 조회 3,835
18년 전 조회 3,335
18년 전 조회 3,377
18년 전 조회 2,565
18년 전 조회 2,464
18년 전 조회 2,450
18년 전 조회 2,320
18년 전 조회 2,554
18년 전 조회 3,852
18년 전 조회 3,653
18년 전 조회 2,082
18년 전 조회 2,019
18년 전 조회 1,554
18년 전 조회 3,888
18년 전 조회 5,890
18년 전 조회 6,985
18년 전 조회 2,468
18년 전 조회 2,711
18년 전 조회 4,168
18년 전 조회 2,172
18년 전 조회 3,618
18년 전 조회 2,874
18년 전 조회 2,731
18년 전 조회 2,201
18년 전 조회 2,464
18년 전 조회 2,593
18년 전 조회 3,088
18년 전 조회 3,733
18년 전 조회 3,273
18년 전 조회 2,779
18년 전 조회 2,272
18년 전 조회 2,940
18년 전 조회 3,030
18년 전 조회 2,541
18년 전 조회 2,298
18년 전 조회 3,331
18년 전 조회 4,850
18년 전 조회 5,068
18년 전 조회 2,294
18년 전 조회 2,186
18년 전 조회 4,995
18년 전 조회 8,960
18년 전 조회 2,046
18년 전 조회 4,924
19년 전 조회 4,363
19년 전 조회 2,605
19년 전 조회 4,961
19년 전 조회 2,788
19년 전 조회 3,667
19년 전 조회 2,620
19년 전 조회 3,433
19년 전 조회 1,944
19년 전 조회 5,376
19년 전 조회 1,694
19년 전 조회 6,052
19년 전 조회 2,871
19년 전 조회 6,037
19년 전 조회 6,831
19년 전 조회 3,724
19년 전 조회 2,204
🐛 버그신고