取 之间 的字符串

newahd 2008-04-05 05:28:19
function getmidstr(L,R,str)

int_left=instr(str,L)
int_right=instr(str,R)

If int_left>0 and int_right>0 Then
getmidstr=mid(str,int_left+len(L),int_right-int_left-len(L))
Else
getmidstr="执行的字符串中不包含“"&L&"”或“"&R&"”"

End If
end function

str="1234567asdfasf[img]111[/img]89safdasfasfasfsfs[img]222[/img]af[img]333[/img]fsf"
response.write "<BR>"&getmidstr("[img]","[/img]",str)
---------------------------------------------------------------------

就是取所有[img][/img]之间的字符
但是以上代码得出的结果是:111,只取到第一串
我要的结果是取文中全部[img][/img]之间的字符并以“|”隔开,结果应该是这样:111|222|333|
代码应该怎么改??
...全文
46 2 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
hookee 2008-04-05
  • 打赏
  • 举报
回复

function getmidstr(L,R,str)

s = ""
int_left = instr(str,L)
int_right = instr(str,R)
While(int_left<>0)
s = s & mid(str,int_left+len(L),int_right-int_left-len(L)) & "|"
int_left = instr(int_right, str,L)
If int_left<>0 Then int_right = instr(int_left, str,R)
Wend
If s<> "" Then s = Left(s, len(s)-1)
getmidstr = s
end Function
  • 打赏
  • 举报
回复
使用正则

28,409

社区成员

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

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