求助 ASP中在一段字符串中查找另一个字符串的代码?

来源:百度知道 编辑:UC知道 时间:2024/05/15 15:41:49
统计字符串
She is a girl.She likes music.She always goes to the movie.
中有多少个"She"

用Vbscript脚本!
回答者:franksee - 魔法学徒 一级
你给的代码是 查找She在字符串中第一次出现的位置!并不是找出 在字符串中有几个She ?

采用字符串匹配函数 InStr([待查找的字符串],[匹配的字符串])

=================================================
例如:
dim num
num = InStr("She is a girl.She likes music.She always goes to the movie. ","She")

++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2007-4-30
是查找第一次出现的位置吗?那么编写一个过程,扫描待查找的字符串,判断是否匹配,然后用个计数器记录,最后返回计数器。

===============================
例如:

Function (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
return count
end function

使用这个过程应该不会出错了!
+++++++++++++++++++++++++++++++++++++++++++++++++++

aa 是个数
aa= InStr("查找的字符串 ","要查找的字符")