过滤字符问题,谢谢!

dcwang 2008-04-18 01:15:52
某字段内容含有文本内容及图片地址。我想只取字符而把图片的地址过滤掉,ASP要如何过滤。谢谢!

例:近年来物价上涨得很厉害,近年来物价上涨得很厉害。<IMG src="http://localhost/UploadFiles/200841503214434.gif"> 我们要想办法解决。

我要过滤<IMG src="http://localhost/UploadFiles/200841503214434.gif">。谢谢!
...全文
96 6 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
Anlige 2008-04-18
  • 打赏
  • 举报
回复

str="近年来物价上涨得很厉害。 <IMG src=""http://localhost/UploadFiles/200841503214434.gif""> 我们要想办法解决。"
Set regEx = New RegExp
dim match
dim cols
regEx.Pattern ="\<img[^\<\>]*\>"
regEx.IgnoreCase = True
regEx.Global = True
str=regex.replace(str,"")
response.write str

str是你要处理的字串
Anlige 2008-04-18
  • 打赏
  • 举报
回复
你可以弄成函数,在必要的时候调用就可以了~
dcwang 2008-04-18
  • 打赏
  • 举报
回复
为了效率我只好不用你说的转义符去弄了。不过还是非常感谢你半夜三更还为我耐心的解答。

直接用str1=rs("content")
intpos=instr(str1,"<IMG")
'response.write intpos
if intpos > 0 then
str2=left(str1,intpos-1)
response.write str2
else
response.write str1
end if
这样做只能先输入文字,然后再传图片就可以解决我如上的问题。
参考了http://topic.csdn.net/u/20070409/11/15d4b95d-b997-4998-92e9-9da1bb958854.html

一并感谢~
aspd199 2008-04-18
  • 打赏
  • 举报
回复
newstr=replace(str,mid(instr(str,' <img'),instr(str,'">')-instr(str,' <img')+1),'')
只替换img标签

注意单双引号
dcwang 2008-04-18
  • 打赏
  • 举报
回复
这样是不是会把<br>之类的也一起过滤的呢。
改成
newstr=replace(str,mid(instr(str," <img"),instr(str,">")-instr(str," <")+1),"")

不知道这样行不?试下。
aspd199 2008-04-18
  • 打赏
  • 举报
回复
str='近年来物价上涨得很厉害,近年来物价上涨得很厉害。 <IMG src="http://localhost/UploadFiles/200841503214434.gif"> 我们要想办法解决。'
newstr=replace(str,mid(instr(str,"<"),instr(str,">")-instr(str,"<")+1),"")

response.write newstr

28,409

社区成员

发帖
与我相关
我的任务
社区描述
ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
社区管理员
  • ASP
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧