CSDN博客

img faintbear

javascript字符串处理

发表于2004/10/20 10:03:00  1019人阅读

script language="javascript">
function Jtrim(str)
 {
 
         var i = 0;
         var len = str.length;
         if ( str == "" ) return( str );
         j = len -1;
         flagbegin = true;
         flagend = true;
         while ( flagbegin == true && i< len)
         {
            if ( str.charAt(i) == " " )
                 {
                   i=i+1;
                   flagbegin=true;
                 }
                 else
                 {
                         flagbegin=false;
                 }
         }
 
         while  (flagend== true && j>=0)
         {
             if (str.charAt(j)==" ")
                 {
                         j=j-1;
                         flagend=true;
                 }
                 else
                 {
                         flagend=false;
                 }
         }
 
         if ( i > j ) return ("")
 
         trimstr = str.substring(i,j+1);
         return trimstr;
 }
 </script>
0 0

相关博文

我的热门文章

img
取 消
img