Advertisement
Aborigenius

CountSubstringOccurences

Aug 22nd, 2017
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.74 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 MiniLab
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             string text = Console.ReadLine().ToLower();
  14.             string repeats = Console.ReadLine().ToLower();
  15.  
  16.             int cnt = 0;
  17.  
  18.             int index = text.IndexOf(repeats);
  19.  
  20.             while (index != -1)
  21.             {
  22.                 cnt++;
  23.                 index = text.IndexOf(repeats, index +1);
  24.             }
  25.             Console.WriteLine(cnt);
  26.  
  27.  
  28.  
  29.      //       string reverse = new string(text.ToCharArray().Reverse().ToArray());
  30.      //       Console.WriteLine(reverse);
  31.         }
  32.     }
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement