如何计算一个字符在一个字符串中出现的次数

fzdcn 2004-04-02 02:48:44
如何计算一个字符在一个字符串中出现的次数
...全文
54 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
7teeth 2004-04-02
  • 打赏
  • 举报
回复
ghostzp(风中一头猪)的思路好
up
ghlfllz 2004-04-02
  • 打赏
  • 举报
回复
<%
sourcestr="asdalkjfsafowerwlkernafadwerlkndvlarewor"
startposition=0
findstr="a"
findcount=0
do while startposition<len(sourcestr)
if startposition=0 then
searchstr=instr(sourcestr,findstr)
else
searchstr=instr(startposition,sourcestr,findstr)
end if
if searchstr<>0 then
findcount=findcount+1
startposition=searchstr+len(findstr)
else
exit do
end if
loopcount=loopcount+1
loop
response.write("结果:"&findcount)
%>
Brookes 2004-04-02
  • 打赏
  • 举报
回复
set re = new RegExp
re.pattern="d"
re.global=true
arr = re.execute("cdbBdbsbdbdz").Count
response.Write(arr)
若白师妹 2004-04-02
  • 打赏
  • 举报
回复
<%str="aabcabaaabbccccca"
tmp=split(str,"a")
response.write ubound(tmp)&"次"
%>
zjwz001 2004-04-02
  • 打赏
  • 举报
回复
打错字了,更正:leg--->len
chenxdb 2004-04-02
  • 打赏
  • 举报
回复
<%
str1="aabcadeaagfaaagahahaaaaa"'要计算的字符串
for i=1 to len(str1)
if Mid(str1, i, 1)="a" then con=con+1
next
'con就是要统计的字个数
%>
a_zhe_20 2004-04-02
  • 打赏
  • 举报
回复
用instr函数吧

然后根据出现的位置截断字符串。循环。
zjwz001 2004-04-02
  • 打赏
  • 举报
回复
dim i,j
str="abcabc"
s="a"
for i=0 to leg(str)
f=mid(str,i,1)
if f=s then
j=j+1
end if
next
response.write j
zjwz001 2004-04-02
  • 打赏
  • 举报
回复
用个循环mid再比较累加起来就OK了

28,391

社区成员

发帖
与我相关
我的任务
社区描述
ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
社区管理员
  • ASP
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧