Advertisement
Guest User

Untitled

a guest
Sep 20th, 2017
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.69 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5.  
  6. namespace RodeIstDoof {
  7.     class Program {
  8.         static void Main(string[] args) {
  9.             String input, pattern;
  10.             int count = 0, lastIndex = -1;
  11.  
  12.             Console.Write("Text: ");
  13.             input = Console.ReadLine().ToLower();
  14.  
  15.             Console.Write("Pattern: ");
  16.             pattern = Console.ReadLine().ToLower();
  17.  
  18.  
  19.             while ((lastIndex = input.IndexOf(pattern, lastIndex + 1)) > -1) {
  20.                     count++;    
  21.             }
  22.  
  23.             Console.WriteLine("Pattern: {0} {1} times", pattern, count);
  24.             Console.ReadLine();
  25.         }
  26.     }
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement