您所在的位置:小祥子 » 编程 » ASP » 正文

ASP截取文章内容为简介函数

时间:2015-02-10 编辑:本站 来源:本站原创

截取文章内容作为简介,肯定得去除一些标记,然后判断截取的字符串与之前的对比,如果以前的很长,还得加点省略号。代码如下

Function gotTopic(str,strlen)
 if str="" then
  gotTopic=""
  exit function
 end if
 dim l,t,c, i
 str=replace(replace(replace(replace(str," "," "),""",chr(34)),">",">"),"<","<")
 l=len(str)
 t=0
 for i=1 to l
  c=Abs(Asc(Mid(str,i,1)))
  if c>255 then
   t=t+2
  else
   t=t+1
  end if
  if t>=strlen then
   gotTopic=left(str,i) & "…"
   exit for
  else
   gotTopic=str
  end if
 next
 gotTopic=replace(replace(replace(replace(gotTopic," "," "),chr(34),"""),">",">"),"<","<")
End Function

关键词:简介 截取 ASP