思路有多种。
- 正则验证匹配
- split分割
- replace替换算长度
下面以第三种方法举例
string strReplace = "http";
int CountHttp = ((strContent.Length – (strContent.Replace(strReplace, string.Empty)).Length)) / strReplace.Length;
实现的思路,想算A字符串在B字符串出现的次数.
可以用 (B字符串的长度, 去除含有的A字符串后的B字符串的长度) 除以A字符串的长度。