asp中常用的几种函数

'截取字符串,不足用空格补上
 Function Cutstr(str,strlen)
  Dim l, t, c, i, strTemp
  str = Replace(Replace(Replace(Replace(str, " ", " "), """, Chr(34)), ">", ">"), "<", "<")
  l = Len(str)
  t = 0
  strTemp = str
  strlen = CLng(strlen)
  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
    strTemp = Left(str, i)
    Exit For
   End If
  Next
  If strTemp <> str Then
   strTemp = strTemp &"..."
  End If
  Cutstr = Replace(Replace(Replace(Replace(strTemp, " ", " "), Chr(34), """), ">", ">"), "<", "<")
 End Function

//////////////////////////////////////

 

'去掉html代码
 Function nohtml(str)
  dim re
  Set re=new RegExp
  re.IgnoreCase =true
  re.Global=True
  re.Pattern="(\<.[^\<]*\>)"
  str=re.replace(str," ")
  re.Pattern="(\<\/[^\<]*\>)"
  str=re.replace(str," ")
  nohtml=Replace(Replace(Replace(Replace(str, " ", " "), """, Chr(34)), ">", ">"), "<", "<")
  set re=nothing
 End function

///////////////////////////////////

function Html_replace(strText)
strText=replace(strText,"",vbCrlf)
 strText=replace(strText,"",vbCrlf)
 strText=replace(strText,"",vbCrlf)
 strText=replace(strText,"",vbCrlf)
 Dim RegEx
 Set RegEx = New RegExp
 RegEx.Pattern = "<[^>]*>"
 RegEx.Global = True
 dim tstr
 tstr = RegEx.Replace(strText, "")
 Set RegEx=nothing
 'tstr=replace(tstr,vbCrlf,"
")
 'tstr=replace(tstr,"

","
")
 'tstr=replace(tstr,"

","
")
 'tstr=replace(tstr,"

","
")
 Html_replace=tstr
 End Function 
///////////////////////////////////////////////

 '去除style
 Function LoseStyleTag(ContentStr)
 Dim ClsTempLoseStr,regEx
 if trim(ContentStr)<>"" then
 ClsTempLoseStr = Cstr(ContentStr)
 Set regEx = New RegExp
 regEx.Pattern = "()+"
 regEx.IgnoreCase = True
 regEx.Global = True
 ClsTempLoseStr = regEx.Replace(ClsTempLoseStr,"")
 end if
 LoseStyleTag = ClsTempLoseStr
 Set regEx = Nothing
 End Function
 

  

posted @ 2013-08-26 14:46  晴耕雨读-li  阅读(22)  评论(0)    收藏  举报