복스리

직접만든 자바스크립트 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,222
18년 전 조회 2,526
18년 전 조회 1,769
18년 전 조회 2,098
18년 전 조회 1,986
18년 전 조회 2,504
18년 전 조회 1,923
18년 전 조회 1,716
18년 전 조회 1,744
18년 전 조회 1,722
18년 전 조회 2,754
18년 전 조회 1,546
18년 전 조회 5,664
18년 전 조회 2,394
18년 전 조회 1,661
18년 전 조회 4,707
18년 전 조회 2,050
18년 전 조회 4,839
18년 전 조회 3,186
18년 전 조회 2,129
18년 전 조회 1,822
18년 전 조회 2,095
18년 전 조회 1,718
18년 전 조회 1,834
18년 전 조회 1,831
18년 전 조회 2,474
18년 전 조회 3,494
18년 전 조회 5,967
18년 전 조회 3,858
18년 전 조회 3,052
18년 전 조회 2,126
18년 전 조회 2,398
18년 전 조회 2,179
18년 전 조회 2,300
18년 전 조회 2,397
18년 전 조회 2,836
18년 전 조회 2,531
18년 전 조회 1,986
18년 전 조회 3,122
18년 전 조회 3,582
18년 전 조회 3,830
18년 전 조회 3,331
18년 전 조회 3,372
18년 전 조회 2,559
18년 전 조회 2,461
18년 전 조회 2,447
18년 전 조회 2,316
18년 전 조회 2,550
18년 전 조회 3,847
18년 전 조회 3,650
18년 전 조회 2,077
18년 전 조회 2,016
18년 전 조회 1,550
18년 전 조회 3,884
18년 전 조회 5,885
18년 전 조회 6,983
18년 전 조회 2,462
18년 전 조회 2,707
18년 전 조회 4,163
18년 전 조회 2,169
18년 전 조회 3,615
18년 전 조회 2,870
18년 전 조회 2,727
18년 전 조회 2,197
18년 전 조회 2,461
18년 전 조회 2,589
18년 전 조회 3,085
18년 전 조회 3,729
18년 전 조회 3,268
18년 전 조회 2,775
18년 전 조회 2,268
18년 전 조회 2,937
18년 전 조회 3,027
18년 전 조회 2,536
18년 전 조회 2,293
18년 전 조회 3,327
18년 전 조회 4,848
18년 전 조회 5,066
18년 전 조회 2,289
18년 전 조회 2,183
18년 전 조회 4,993
18년 전 조회 8,956
18년 전 조회 2,042
18년 전 조회 4,919
18년 전 조회 4,359
18년 전 조회 2,602
18년 전 조회 4,956
18년 전 조회 2,784
18년 전 조회 3,663
19년 전 조회 2,616
19년 전 조회 3,429
19년 전 조회 1,939
19년 전 조회 5,369
19년 전 조회 1,689
19년 전 조회 6,048
19년 전 조회 2,867
19년 전 조회 6,033
19년 전 조회 6,828
19년 전 조회 3,720
19년 전 조회 2,201
🐛 버그신고