您的位置:首页 > 其它

得到str1在str2中出现的次数 GetCountInStr(string str1,string str2)

2006-03-09 10:22 267 查看
/// <summary>
/// 得到str1在str2中出现的次数
/// </summary>
/// <param name="str1"></param>
/// <param name="str2"></param>
/// <returns></returns>
public static int GetCountInStr(string str1,string str2){
int count = 0;
int str1Len = str1.Length;
for(int i=0;i<=str2.Length-str1Len;i++){
if(str2.Substring(i,str1Len) == str1)
count ++;
}
return count;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐