截字符串 去除HTML標記
更新時間:2006年06月17日 00:00:00 作者:
<%
'**************************************************
'函數(shù)名:gotTopic
'作 用:截字符串,漢字一個算兩個字符,英文算一個字符
'參 數(shù):str ----原字符串
' strlen ----截取長度
'返回值:截取后的字符串
'**************************************************
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)),">",">"),"<","<")
str=replace(str,"?","")
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
'=========================================================
'函數(shù):RemoveHTML(strHTML)
'功能:去除HTML標記
'參數(shù):strHTML --要去除HTML標記的字符串
'=========================================================
Function RemoveHTML(strHTML)
Dim objRegExp, Match, Matches
Set objRegExp = New Regexp
objRegExp.IgnoreCase = True
objRegExp.Global = True
'取閉合的<>
objRegExp.Pattern = "<.+?>"
'進行匹配
Set Matches = objRegExp.Execute(strHTML)
' 遍歷匹配集合,并替換掉匹配的項目
For Each Match in Matches
strHtml=Replace(strHTML,Match.Value,"")
Next
RemoveHTML=strHTML
Set objRegExp = Nothing
set Matches=nothing
End Function
%>
'**************************************************
'函數(shù)名:gotTopic
'作 用:截字符串,漢字一個算兩個字符,英文算一個字符
'參 數(shù):str ----原字符串
' strlen ----截取長度
'返回值:截取后的字符串
'**************************************************
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)),">",">"),"<","<")
str=replace(str,"?","")
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
'=========================================================
'函數(shù):RemoveHTML(strHTML)
'功能:去除HTML標記
'參數(shù):strHTML --要去除HTML標記的字符串
'=========================================================
Function RemoveHTML(strHTML)
Dim objRegExp, Match, Matches
Set objRegExp = New Regexp
objRegExp.IgnoreCase = True
objRegExp.Global = True
'取閉合的<>
objRegExp.Pattern = "<.+?>"
'進行匹配
Set Matches = objRegExp.Execute(strHTML)
' 遍歷匹配集合,并替換掉匹配的項目
For Each Match in Matches
strHtml=Replace(strHTML,Match.Value,"")
Next
RemoveHTML=strHTML
Set objRegExp = Nothing
set Matches=nothing
End Function
%>
相關文章
[js]用JAVASCRIPT正則表達式限制文本字節(jié)數(shù)的代碼
[js]用JAVASCRIPT正則表達式限制文本字節(jié)數(shù)的代碼...2007-11-11javascript RegExp multiline多行匹配影響的^$
javascript RegExp multiline多行匹配影響的^$,代碼中有詳細的注釋,方法大家學習。2010-03-03c# 正則表達式對網(wǎng)頁進行有效內(nèi)容抽取
本問主要總結了用正則表達式對網(wǎng)頁進行有效內(nèi)容提取的具體實現(xiàn)方法,并給出了c#代碼2009-03-03