C#判斷字符串compare 在 input字符串中出現的次數

 /// <summary>From:www.uzhanbao.com
         /// 判斷字符串compare 在 input字符串中出現的次數
         /// </summary>
         /// <param name="input">源字符串</param>
         /// <param name="compare">用於比較的字符串</param>
         /// <returns>字符串compare 在 input字符串中出現的次數</returns>
         private static int GetStringCount(string input, string compare)
         {
             int index = input.IndexOf(compare);
             if (index != -1)
             {
                 return 1 + GetStringCount(input.Substring(index + compare.Length), compare);
             }
             else
             {
                 return 0;
             }
 
         }

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章