ASP实现长文章自动分页的函数代码

2013 年 6 月 6 日4490

以下是引用片段:
  Functionc2u(myText)
  Dimi
  c2u=""
  Fori=1toLen(myText)
  c2u=c2u&"&#x"&Hex(AscW(Mid(myText,i,1)))&";"
  Next
  EndFunction

以下是引用片段:
  FunctioncutStr(str,strlen)
  '去掉所有HTML标记
  Dimre
  Setre=newRegExp
  re.IgnoreCase=True
  re.Global=True
  re.Pattern="<(.[^>]*)>"
  str=re.Replace(str,"")
  setre=Nothing
  Diml,t,c,i
  l=Len(str)
  t=0
  Fori=1tol
  c=Abs(Asc(Mid(str,i,1)))
  Ifc>255Then
  t=t+2
  Else
  t=t+1
  EndIf
  Ift>=strlenThen
  cutStr=left(str,i)&"..."
  ExitFor
  Else
  cutStr=str
  EndIf
  Next
  cutStr=Replace(cutStr,chr(10),"")
  cutStr=Replace(cutStr,chr(13),"")
  EndFunction

以下是引用片段:
  Functionconverttowide(str)
  Dimstrlen
  Dimposition
  Dimconvertstr
  ifisnull(str)then
  converttowide=str
  else
  position=1
  strlen=Len(str)
  Fori=1Tostrlen
  convertstr=convertstr+"&#x"+Hex(AscW(Mid(str,position,1)))+";"
  position=position+1
  Next
  converttowide=convertstr
  endif
  EndFunction

以下是引用片段:
  dimtopicx,usernamex,addtimex,logtextx,ispassword
  '获取ID号
  articleid=request("articleid")
  '写执行语句
  strSQL="select*fromarticlewherearticleid="&articleid&""
  '接上面函数
  logtextx=cutStr(rs("content"),5000)
  '开始分页
  dimpage,PageLength,CLength,PageCount,wen,a
  ifRequest("Page")<>""thenPage=CLng(Request("Page"))
  PageLength=80
  CLength=Len(logtextx)
  PageCount=Int(Clength/PageLength)+1
  ifPage<1orIsNull(Page)ThenPage=1
  ifPage>PageCountThenPage=PageCount
  ifpage=1then
  a=1
  elseifpage>1then
  a=(Page-1)*PageLength
  endif
  wen=Mid(logtextx,a,PageLength)
  '判断
  ifpage=""orpage=1then
  '开始显示内容
  Response.write(c2u("内容:"))'http://www.zjjv.com/
  endif
  Response.write(converttowide(wen))
  Response.write "<br/>"
  'Response.write (converttowide("本文字数:")) & CLength &"<br/>"
  Response.write (c2u("本文被分为")) & PageCount & (converttowide("页"))&""&c2u("当前为"&Page&"页")&"<br/>"
  ifPageCount>1andpage<>1then'http://www.zjjv.com/
  Response.write"1"
  endif
  dimj
  Forj=Page+1ToPage+10
  ifj<=PageCount-1then
  Response.write""&j&""
  endif
  next
  ifPageCount>1andPage<>PageCountthen
  Response.write "<a href="/"showarticle.asp?articleid="&articleid&"&Page="&PageCount&""">"&PageCount&"</a><br/>"
  Endif
  '结束

  以上代码在WIN2000+IIS5、WIN2003+IIS6 上执行通过


阅读关于 的全部文章

0 0