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

[求助]应该算是返回字符串的问题吧??

utfqqrsf 发布于 2007-08-27 11:46, 388 次点击
问题是这样的

我在数据库读出数据rs("text"),现在我想假如这个rs("text")中包含[ img ]*[/img]
便在rs("text")前面加上“[组图]”

其中*号为任意URL

具体应该怎样做??

[此贴子已经被作者于2007-8-27 13:56:07编辑过]

4 回复
#2
yms1232007-08-27 12:36

Function getImgStr(Str)
Dim ReVal
ReVal=Replace(Str,"[img]","[组图][img]")
getImgStr=ReVal
End Function
运用Replace查找和替换函数进行替换即可。
Replace([原始字符串],[查找的字符串],[替换的字符串])

#3
utfqqrsf2007-08-27 13:55
我不是这个意思

是在rs("text")前加[组图]

也就是有[img]的话,就
[组图]+rs("text")

没有就
rs("text")

谢版主了~~~
#4
hmhz2007-08-27 15:48
判断
Function getImgStr(strng)
getImgStr=false
Dim RegEx, Match
Set RegEx = New RegExp
Regex.pattern = "^[img]$"
RegEx.IgnoreCase = True
Set Match = RegEx.Execute(strng)
if match.count then getImgStr=True
End Function

if not(getImgStr(rs("text"))) then
response.write "[组图] "&rs("text")
else
response.write rs("text")
end if
#5
utfqqrsf2007-08-28 09:29

Function getImgStr(strng)
getImgStr=false
Dim RegEx, Match
Set RegEx = New RegExp
Regex.pattern = "[img]" Regex.pattern = "^[img]$"
RegEx.IgnoreCase = True
Set Match = RegEx.Execute(strng)
if match.count then getImgStr=True
End Function

if getImgStr(rs("text")) then if not(getImgStr(rs("text"))) then
response.write("[组图]"&rs("text"))
else
...............
end if

我改了这两处便行了~~~~谢谢楼上的
还有能解释一下这个Function的意思吗??
主要是那个pattern是怎样用的??

1