不锈钢香皂有用吗:vb程序如何判断一个子字符串在一个字符串中出现的次数???

来源:百度文库 编辑:杭州交通信息网 时间:2024/05/12 13:13:58
vb程序如何判断一个子字符串在一个字符串中出现的次数???

楼上的程序有些小问题
start=temp+length应改为start=start+1
比如x1x在x1x1x中出现的次数应为2而不是1

改为
start=1
n=0
Do
temp=Instr(start,string,keyword)
If temp<>0 then
n = n + 1
start=start+1
Else
Exit Do
end if
Loop
Msgbox n

start=1
n=0
length=Len(keyword)
Do
temp=Instr(start,string,keyword)
If temp<>0 then
n = n + 1
start=temp+length
Else
Exit Do
Loop
Msgbox n