ASP的过滤字符问题。

来源:百度知道 编辑:UC知道 时间:2024/05/10 13:21:51
我想要过滤"http://"和"href="这两个字符,如果http://出现两次或href=出现一次,则。。。
我原来是这样写的:
if instr(book_bz,"http://")>1 or instr(book_bz,"href=")>0 then
...
但是好象不对,请问我应该怎么写?

if ubound(split(lcase(book_bz),"http://"))>1 or ubound(split(lcase(book_bz),"href="))>0 or ubound(split(lcase(book_bz),"src="))>0 then

split(text,"http://")
把 text 以 http:// 隔开,转换为一个数组
如果有一个 http:// ,得到一个两行的数组
如果有两个 http:// ,就会得到一个三行的数组

ubound 返回数组的最大下标,因为下标是从0开始编号的,所以两行的数组最大下标是1
只要大于1,就说明有至少两个 http://

另外一个方法:
可以replace掉http://看最后是否长度少了两个http://共14个字符,呵!

instr这个是出现的位置并不是次数,
下面我们就来做一个检测一个字符串在另一个字符串当中出现几次的函数:
Function CheckTheChar(TheChar,TheString)
'TheChar="要检测的字符串"
'TheString="待检测的字符串"
if inStr(TheString,TheChar) then
for n =1 to Len(TheString)
if Mid(TheString,n,Len(TheChar))=TheChar then
CheckTheChar=CheckTheChar+1
End if
Next
CheckTheChar="这个字符"&CheckTheChar&"次"
else
CheckTheChar="0次"
end if
End Function