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=str set re=nothing End Function
或者
Function noHtml(str) dim re Set re=new RegExp re.IgnoreCase =true re.Global=True re.Pattern="<(.[^>]*)>" str=re.replace(str,"") noHtml=str set re=nothing End Function
做過簡單的應用。
[Ctrl+A 全部選擇 提示:你可先修改部分代碼,再按運行]
附帶“過濾Html代碼並截取”的代碼
Function cutStr(str,strlen) Dim re Set re=new RegExp re.IgnoreCase =True re.Global=True re.Pattern="<(.[^>]*)>" str=re.Replace(str,"") set re=Nothing Dim l,t,c,i 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 cutStr=left(str,i)&"..." Exit For Else cutStr=str End If Next cutStr=Replace(cutStr,chr(10),"") cutStr=Replace(cutStr,chr(13)," ") cutStr=Replace(cutStr," ","") End Function