ASP去除HTML标记和截取字符串加强的函数<br /> =========================================================<br /> '函数:RemoveHTML(strHTML)<br /> '功能:去除HTML标记<br /> '参数:strHTML --要去除HTML标记的字符串<br /> '=========================================================<br /> Function RemoveHTML(strHTML) <br /> Dim objRegExp, Match, Matches <br /> Set objRegExp = New Regexp <br /> objRegExp.IgnoreCase = True <br /> objRegExp.Global = True <br /> '取闭合的&lt;&gt; <br /> objRegExp.Pattern = &quot;&lt;.+?&gt;&quot; <br /> '正则表达式进行匹配 <br /> Set Matches = objRegExp.Execute(strHTML) <br /> ' 遍历匹配集合,并替换掉匹配的项目 <br /> For Each Match in Matches <br /> strHtml=Replace(strHTML,Match.Value,&quot;&quot;) <br /> Next <br /> RemoveHTML=strHTML <br /> Set objRegExp = Nothing <br /> set Matches=nothing<br /> End Function <br /> %&gt; <br /> <br /> ASP截取字符串加强的函数:<br /> &lt;%'**************************************************<br /> '函数名:gotTopic<br /> '作 用:截字符串,汉字一个算两个字符,英文算一个字符<br /> '参 数:str ----原字符串<br /> ' strlen ----截取长度<br /> '返回值:截取后的字符串<br /> '**************************************************<br /> function gotTopic(str,strlen)<br /> if str=&quot;&quot; then<br /> gotTopic=&quot;&quot;<br /> exit function<br /> end if<br /> dim l,t,c, i<br /> str=replace(replace(replace(replace(str,&quot; &quot;,&quot; &quot;),&quot;&quot;&quot;,chr(34)),&quot;&gt;&quot;,&quot;&gt;&quot;),&quot;&lt;&quot;,&quot;&lt;&quot;)<br /> str=replace(str,&quot;?&quot;,&quot;&quot;)<br /> l=len(str)<br /> t=0<br /> for i=1 to l<br /> c=Abs(Asc(Mid(str,i,1)))<br /> if c&gt;255 then<br /> t=t+2<br /> else<br /> t=t+1<br /> end if<br /> if t&gt;=strlen then<br /> gotTopic=left(str,i) &amp; &quot;…&quot;<br /> exit for<br /> else<br /> gotTopic=str<br /> end if<br /> next<br /> gotTopic=replace(replace(replace(replace(gotTopic,&quot; &quot;,&quot; &quot;),chr(34),&quot;&quot;&quot;),&quot;&gt;&quot;,&quot;&gt;&quot;),&quot;&lt;&quot;,&quot;&lt;&quot;)<br /> end function
T:0.007536s,M:246.55 KB
返回顶部 留言