- #region 获取某一字符串在字符串中出现的次数
- /// <summary>
- /// 获取某一字符串在字符串中出现的次数
- /// </summary>
- /// <param name="stringArray" type="string">
- /// <para>
- /// 原字符串
- /// </para>
- /// </param>
- /// <param name="findString" type="string">
- /// <para>
- /// 匹配字符串
- /// </para>
- /// </param>
- /// <returns>
- /// 匹配字符串数量
- /// </returns>
- public static int GetStringCount(string sourceString, string findString)
- {
- int count = 0;
- int findStringLength = findString.Length;
- string subString = sourceString;
- while (subString.IndexOf(findString) >= 0)
- {
- subString = subString.Substring(subString.IndexOf(findString) + findStringLength);
- count += 1;
- }
- return count;
- }
- #endregion
-
复制代码 希望能帮助到大家! |