取字串的顯示長度leftStr(str,leni)

來源:互聯網
上載者:User
  1. <%@LANGUAGE="VBSCRIPT" CODEPAGE="936"%>
  2. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
  3. <html>
  4. <head>
  5. <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
  6. <title>測試LEFTSTR</title>
  7. </head>
  8. <body>
  9. <%
  10. response.Write LeftStr("如果I'am如果I'am如果I'am如果I'am如果I'am如果I'am如果I'am",12)&"</br>"
  11. response.Write LeftStr("1234567890123456789012345678901234567890123456789012345678901234567890",12)&"</br>"
  12. response.Write LeftStr("如果我是上帝,必要殺盡天下天使,洗盡其傳承自遠古的不淨!",12)&"</br>"
  13. response.Write LeftStr("1234567890",12)&"</br>"
  14. response.Write LeftStr("必要殺盡天!",12)&"</br>"
  15. Function LeftStr(str,leni)
  16.     Dim     L,sL,Acode
  17.     l=0 '當前所在位置
  18.     sL=len(str) '最高位置,即長度
  19.     for i=1 to leni*2   '將漢字看成2,所以顯示長度最大為leni*2
  20.         l=L+1   '位置+1
  21.         Acode=ASC(Mid(str,L,1)) '取ASC碼
  22.         if Acode<0 or Acode>256 then II=I+1  '非ASCII字元則認為是漢字
  23.         if l>=sl then exit for  '如果長度將超過字串長度即退出
  24.     next
  25.     LeftStr =left(str,l)    '得到所需的字元
  26. End Function
  27. %>
  28. </body>
  29. </html>

因解決ywqxtx
http://topic.csdn.net/u/20080927/10/90701d05-13ad-4757-98a9-6904500739b5.html

而寫

 

寫了就收藏下,省得以後,還是白手寫~~~

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.