注册 登录
编程论坛 ASP技术论坛

麻烦各位个问题有关字符截取的

richceo 发布于 2009-10-23 14:44, 498 次点击
各位帮帮忙
我的程序想显示部分文字但是详细信息里面还有图片 怎么只获取页面文字不获取图片啊
if len(trim(rs("bookcontent")))>120 then
            response.write left(trim(rs("bookcontent")),120)&".."
            else
            response.write trim(rs("bookcontent"))
            end if
            response.write "</font>"

bookcontent里面有图片但是我不想显示图片想显示bookcontent里的文字
6 回复
#2
yms1232009-10-23 15:11
用Replace函数把图片HTML代码过滤掉。
#3
aspic2009-10-23 15:17
程序代码:
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,"")
        strHtml=Trim(Replace(strHtml," ",""))
    Next
    RemoveHTML=strHTML
    Set objRegExp = Nothing
End Function
#4
richceo2009-10-23 15:49
回复 3楼 aspic
头 我真不会弄加了代码后错误
#5
aspic2009-10-23 16:31
需要显示的地方<%=RemoveHTML(你原来的数据)%>
#6
aspic2009-10-23 16:32
或者response.write RemoveHTML(你原来的数据)
#7
chenbofeng202009-10-24 10:21
把以下代码放入数据库连接页面中
Function RemoveHTML( strText )  
    Dim RegEx  
    Set RegEx = New RegExp  
    RegEx.Pattern = "<[^>]*>"  
    RegEx.Global = True  
RemoveHTML = RegEx.Replace(strText, "")  
在本页面:
bookcontent=RemoveHTML(rs("bookcontent"))
if len(bookcontent)> 120 then
  response.write left(bookcontent,120)&"..."
else
  response.write bookcontent
end if
   response.write "</font>"
1