大航海时代5 设置商馆:vb程序如何判断一个子字符串在一个字符串中出现的次数???
来源:百度文库 编辑:神马品牌网 时间:2024/04/30 20:29:11
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