-Annie-

CountSubstringOccurrences

May 31st, 2016
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.63 KB | None | 0 0
  1. namespace CountSubstringOccurrences
  2. {
  3.     using System;
  4.  
  5.     public class CountSubstringOccurrences
  6.     {
  7.         public static void Main()
  8.         {
  9.             string input = Console.ReadLine().ToLower();
  10.             string pattern = Console.ReadLine().ToLower();
  11.             int occurencesCounter = 0;
  12.             int indexOfOccurences = input.IndexOf(pattern);
  13.  
  14.             while (indexOfOccurences!=-1)
  15.             {
  16.                 occurencesCounter++;
  17.                 indexOfOccurences = input.IndexOf(pattern, indexOfOccurences + 1);
  18.             }
  19.  
  20.             Console.WriteLine(occurencesCounter);
  21.         }
  22.     }
  23. }
Advertisement
Add Comment
Please, Sign In to add comment