啊啊啊啊 这个问题哪个帮我看看

CYCYKK 2006-11-02 09:41:15
怎么判断一个字符串里某个字符串出现的次数啊
...全文
51 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
lizhizhe2000 2006-11-02
  • 打赏
  • 举报
回复
用IndexOf吧
需要循环处理
tangyong12 2006-11-02
  • 打赏
  • 举报
回复
方法一:
private int RepeatNumber(string strSource,string strFind)
{
int intLastFind;
int intNumber;
intNumber=1;
intLastFind=strSource.IndexOf(strFind);
while(intLastFind>0)
{
intNumber++;
intLastFind=strSource.IndexOf(strFind,intLastFind+1);
}
return intNumber;
}
方法二:
string str = "abcdabcabcdabsdfewabdfsfabcfdsfdsafabwerwrabcd";
int count = 0;
string findstr = "abcd";
count = (str.Length - str.Replace(findstr,string.Empty).Length)/findstr.Length;

110,534

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

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