asp字串截取函數

來源:互聯網
上載者:User

'本文章提供這款asp字串截取函數原是是先用定義字串判別函數判斷字串長度以及中英文,再把字元截取後定義超出部分內容的...顯示方式

function strvalue(str,lennum)
dim p_num
dim i
if strlen(str)<=lennum then
strvalue=str
else
p_num=0
x=0
do while not p_num > lennum-2
x=x+1
if asc(mid(str,x,1))<0 then
p_num=int(p_num) + 2
else
p_num=int(p_num) + 1
end if
strvalue=left(trim(str),x)&"…" '截取後定義超出部分內容的顯示方式
loop
end if
end function

'定義字串判別函數www.111cn.net
function strlen(str)
dim p_len
p_len=0
strlen=0
if trim(str)<>"" then
p_len=len(trim(str))
for xx=1 to p_len
if asc(mid(str,xx,1))<0 then
strlen=int(strlen) + 2
else
strlen=int(strlen) + 1
end if
next
end if
end function

''截取字串,1.包括前後字串,2.不包括前後字串
function strcut(strcontent,startstr,endstr,cuttype)
dim s1,s2
on error resume next
select case cuttype
case 1
  s1 = instr(strcontent,startstr)
  s2 = instr(s1,strcontent,endstr)+len(endstr)
case 2
  s1 = instr(strcontent,startstr)+len(startstr)
  s2 = instr(s1,strcontent,endstr)
end select
if err then
  strcute = "<p align='center' ><font size=-1>截取字串出錯.</font></p>"
  err.clear
  exit function
else
  strcut = mid(strcontent,s1,s2-s1)
end if
end function

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.