Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- class CountStringOccurrences
- {
- static void Main()
- {
- string input = Console.ReadLine();
- string searchFor = Console.ReadLine();
- Console.WriteLine(CountSubstrings(input, searchFor));
- }
- static int CountSubstrings (string text, string substring)
- {
- int counter = 0, index = 0;
- while ((index < text.Length) && index != -1)
- {
- counter++;
- index = text.IndexOf(substring, index + substring.Length);
- }
- return counter;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement