Advertisement
Guest User

03. Count Substring Occurrences

a guest
May 13th, 2015
378
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.66 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. class CountSubstringOccurrences
  8. {
  9.     static void Main()
  10.     {
  11.         string text = Console.ReadLine();
  12.         string searchWord = Console.ReadLine();
  13.  
  14.         int count = 0;
  15.         string search;
  16.  
  17.         for (int i = 0; i < text.Length - searchWord.Length + 1; i++)
  18.         {
  19.             search = text.Substring(i, searchWord.Length);
  20.             if (string.Equals(search, searchWord, StringComparison.OrdinalIgnoreCase))
  21.             {
  22.                 count++;
  23.             }
  24.         }
  25.         Console.WriteLine(count);
  26.     }
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement