Advertisement
Guest User

Untitled

a guest
Jan 27th, 2013
245
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.98 KB | None | 0 0
  1. using System;
  2.  
  3. class Program
  4. {
  5.  
  6.     public static int CountSubstring(string text, string subtr)
  7.     {
  8.         int count = 0;
  9.         text = text.ToLower();
  10.         while (text.IndexOf(subtr) != -1)
  11.         {
  12.             int pos = text.LastIndexOf(subtr);
  13.             if (text.Substring(pos, subtr.Length) != "")
  14.             {
  15.                 count++;
  16.                 text = text.Remove(pos);
  17.             }
  18.         }
  19.         return count;
  20.     }
  21.  
  22.     static void Main()
  23.     {
  24.         string text = "We are living in a yellow submarine. We don't have anything else. Inside the submarine is very tight. So we are drinking all the day. We will move out of it in 5 days.";
  25.         string word = " in ";
  26.         string[] sentences = text.Split('.');
  27.  
  28.         for (int i = 0; i < sentences.Length; i++)
  29.         {
  30.             if (CountSubstring(sentences[i], word) > 0)
  31.             {
  32.                 Console.WriteLine((sentences[i] + ".").Trim());
  33.             }
  34.         }
  35.     }
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement