查找:ASP中在一段字符串中查找另一个字符串的代码的问题?

来源:百度知道 编辑:UC知道 时间:2024/05/16 00:59:55
%
function ch(str1,str2)

dim n,m,ss,count
n=len(str1)
m=len(str2)
count=0
for i=1 to n step m
if mid(str1,i,m)=str2 then
count=count+1
end if
next
response.write count

End function

call ch("She is a girl.She likes music.She always goes to the movie. ","She")
%>上面代码是从She is a girl.She likes music.She always goes to the movie.里面找出有几个She,我测试了一下,却是2!
问那一点错了!高手给个回答!
谢谢
这代码是别人给说的!我刚学ASP,什么都不懂!
我测试下,看能用不!

call ch("She is a girl.She likes music.1She always goes to the movie. ","She")

你如果像上面那样调用只能为1了,因为你循环的时候步进(step)设置太大了,不知道是不是你故意的。


for i=1 to n step m
改成
for i=1 to n step 1

就行了。那么字符串里面有多少就会得到多少。

for i=1 to n step m 改成step 1

思路错的
应该是一个一个比不能设置长度
function ch(str1,str2)

dim n,m,ss,count
n=len(str1)
m=len(str2)
count=0
for i=1 to n
if mid(str1,i,m)=str2 then
count=count+1
end if
next
response.write count

End function