Advertisement
petromaxa

Untitled

Jan 31st, 2013
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.83 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5.  
  6. namespace _4.SearchSubstring
  7. {
  8. class SearchSubstring
  9. {
  10. static void Main()
  11. {
  12. string str = "We are living in an 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.";
  13. string searchedPattern = "in";
  14.  
  15. str = str.ToUpper();
  16. string newSearchedPattern = searchedPattern.ToUpper();
  17. string newString = str.Replace(newSearchedPattern, "");
  18.  
  19. int numberOfTimes = (str.Length - newString.Length) / searchedPattern.Length;
  20. Console.WriteLine("Searched pattern \"{0}\" is found {1} times in the string!",searchedPattern,numberOfTimes);
  21. }
  22. }
  23. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement