Advertisement
Guest User

Untitled

a guest
May 21st, 2016
680
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.09 KB | None | 0 0
  1. namespace Debugging_Substring
  2. {
  3. using System;
  4.  
  5. public class Substring_broken
  6. {
  7. public static void Main()
  8. {
  9. string text = Console.ReadLine();
  10. int jump = int.Parse(Console.ReadLine());
  11.  
  12. const char Search = 'p';
  13. bool hasMatch = false;
  14.  
  15. for (int i = 0; i < text.Length; i++)
  16. {
  17. if (text[i] == Search)
  18. {
  19. hasMatch = true;
  20.  
  21. int length = jump + 1;
  22. string matchedString;
  23. if (i + length <= text.Length)
  24. {
  25. matchedString = text.Substring(i, length);
  26. }
  27. else
  28. {
  29. matchedString = text.Substring(i);
  30. }
  31.  
  32. Console.WriteLine(matchedString);
  33. i += jump;
  34. }
  35. }
  36.  
  37. if (!hasMatch)
  38. {
  39. Console.WriteLine("no");
  40. }
  41. }
  42. }
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement