ubb的实现原理无外乎字符串的查找和替换。因此microosft script engine 5.0版本的regexp(正则表达式对象)是个不错的选择,但我想由于isp的关系,我现在这个网站(信诺立)就还不支持microsoft script engine 5.0。所以下面这个子程序可能更适合大家一些。
□convert-实现ubb标记的查找和替换,当前实现了b/url/url1(在一个新窗口中打开链接)/#/hr等多个标记,大家可以自己增加其他标记。
□调用方法
if convert(text,"url")=false then
url标记错误处理
end if
□convert函数代码
function convert(byref intext, ubb)
变量定义
dim intstart
dim intstartpostion
dim intendpostion
dim strstartubb
dim strendubb
dim intstartubblen
dim intendubblen
dim intstrlen
intstrlen = len(intext)
dim strcontent
dim strfinish
彩色标记
dim strcolor
#号ubb开始标记的结束]位置
dim intjhendpostion
intstart = 1
if ubb = "#" then
strstartubb = "[" & "#"
else
strstartubb = "][" & ubb & "]"
end if
if ubb = "hr" then
intstartpostion = instr(intstart, intext, strstartubb, 1)
do until intstartpostion=0
intext = replace(intext, strstartubb, "<hr size=1>", 1, -1, 1)
intstart=intstartpostion+len(strstartubb)
intstartpostion = instr(intstart, intext,strstartubb, 1)
loop
convert=true
exit function
end if
strendubb = "[/" & ubb & "]"
intstartubblen = len(strstartubb)
intendubblen = len(strendubb)
intstartpostion = instr(intstart, intext, strstartubb, 1)
do until intstartpostion = 0
找匹配ubb
intendpostion = instr(intstart, intext, strendubb, 1)
if intendpostion = 0 then
convert = false
exit function
else
取中间字符串
if ubb = "#" then
#号特殊处理
intjhendpostion = instr(intstartpostion, intext, "]")
if intjhendpostion = 0 then
convert = false
exit function
end if
strcolor = mid(intext, intstartpostion + intstartubblen, intjhendpostion - intstartpostion - intstartubblen)
strcontent = mid(intext, intstartpostion + intstartubblen + len(strcolor) + 1, intendpostion - intstartpostion - intstartubblen - len(strcolor) - 1)
else
strcontent = mid(intext, intstartpostion + intstartubblen, (intendpostion - intstartpostion - intstartubblen))
end if
ubb处理
select case ucase(ubb)
黑体
case "b"
strfinish = "<b>" & strcontent & "</b>"
case "url"
strfinish = "<a href=" & strcontent & ">" & strcontent & "</a>"
你可以增加其他标记
case "url1"
在另一个窗口打开
strfinish = "<a href=" & strcontent & " target=_blank>" & strcontent & "</a>"
case "img"
strfinish = "<img src=" & strcontent & ">"
case "#"
strfinish = "<font color=#" & strcolor & ">" & strcontent & "</font>"
end select
替换
if ubb = "#" then
intext = replace(intext, strstartubb & strcolor & "]" & strcontent & strendubb, strfinish, 1, -1, 1)
else
intext = replace(intext, strstartubb & strcontent & strendubb, strfinish, 1, -1, 1)
end if
end if
intstart = intstartpostion + 1
intstartpostion = instr(intstart, intext, strstartubb, 1)
loop
convert = true
end function
//站长:webmaster@chinaasp.com 注:此段代码不是chinaasp采用的代码,chinaasp的代码是露茜所作,
文章整理:站长天空 网址:http://www.z6688.com/
以上信息与文章正文是不可分割的一部分,如果您要转载本文章,请保留以上信息,谢谢!




