Advertisement
Militsa

02.Count Substring Occurrences

Nov 29th, 2017
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.63 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace _02.Count_Substring_Occurrences
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             string text = Console.ReadLine().ToLower();
  14.             string pattern = Console.ReadLine().ToLower();
  15.             int count = 0;
  16.             int index = text.IndexOf(pattern);
  17.             while (index != -1)
  18.             {
  19.                 count++;
  20.                 index = text.IndexOf(pattern, index + 1);
  21.             }
  22.             Console.WriteLine(count);
  23.         }
  24.     }
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement