熱點推薦:
您现在的位置: 電腦知識網 >> 編程 >> Java編程 >> JSP教程 >> 正文

關於字符串的幾個有用函數

2022-06-13   來源: JSP教程 

  測試字符串長度(中英文)

  function strLen(s)
{
 var istrstrstrnLen;
 str = svalue;
 nLen = ;
 for(i=;i<=strlength;i++)
 {
  str=strsubstring(ii)
  str=escape(str);
  if(strlength>)
   {
    nLen = nLen + ;
   }
  else
   {
    nLen = nLen + ;
   }
 }
 return nLen;
}
替換

  function Replace(sss)
{
 var len len i;
 var str str ;
 str = s;
 len = strlength;
 len = slength;
 if (len > len)
  return s;
 for (i=;i<= lenlen+ ; i++)
     {
   
   str = strsubstring(ii+len);
   if (str == s)
    {
     str = strsubstring(i) + s + strsubstring(i+lenlen );
     i = ;
     len = strlength;
    }
     }
 return str;
}

  查找
function Pos(ss)
{
 var len len iflag;
 var str str ;
 str = s;
 len = strlength;
 len = slength;
 if (len== || len==)
     return ;
 flag = false;
 if (len > len)
  return s;
 for (i=;i<= lenlen+ ; i++)
     {
   
   str = strsubstring(ii+len);
   if (str == s)
    {
     flag = true;
     break;
    }
     }
 if (flag)
  return i;
 else
  return ;
}


From:http://tw.wingwit.com/Article/program/Java/JSP/201311/19122.html
    推薦文章
    Copyright © 2005-2022 電腦知識網 Computer Knowledge   All rights reserved.