Advertisement
AlexPopov

Untitled

Jan 24th, 2013
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.77 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 Occurances
  8. {
  9.     class Occurances
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             Console.WriteLine("Enter some text:");
  14.             string text = Console.ReadLine();
  15.             Console.WriteLine("Enter a string to search for:");
  16.             string word = Console.ReadLine();
  17.  
  18.             int count = 0;
  19.  
  20.             for (int i = 0; i < text.Length - word.Length + 1; i++)
  21.             {
  22.                 if (string.Compare(text.Substring(i, word.Length), word, true) == 0)
  23.                 {
  24.                     count++;
  25.                 }
  26.             }
  27.  
  28.             Console.WriteLine(count);
  29.         }
  30.     }
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement