asp 记录某字符串中某字符的个数

各位高手怎么用asp记录某字符在字符串中出现的次数啊
2025-02-25 22:21:10
推荐回答(1个)
回答1:

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

第二种:
<%
Function getCount(s,subs)
temp = s
count= 0
while(instr(s,subs)>0)
response.write s & "
"
count = count + 1
s = right(s,len(s) - instr(s,subs))

Wend
getCount = count
End Function

s = "我们建议这样做好,他们不建议这样做!怎么办?"
subs="建议"

response.write getCount(s,subs)
%>