asp 记录某字符串中某字符的个数
发布网友
发布时间:2022-11-18 07:12
我来回答
共1个回答
热心网友
时间:2024-12-05 17:55
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 & "<BR>"
count = count + 1
s = right(s,len(s) - instr(s,subs))
Wend
getCount = count
End Function
s = "我们建议这样做好,他们不建议这样做!怎么办?"
subs="建议"
response.write getCount(s,subs)
%>