Advertisement
Guest User

Untitled

a guest
Aug 5th, 2016
152
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.08 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. const char Search = 'p';
  12. bool hasMatch = false;
  13. for (int i = 0; i < text.Length; i++)
  14. {
  15. if (text[i] == Search)
  16. {
  17. hasMatch = true;
  18. int length = jump + 1;
  19. string matchedString;
  20. if (i + length <= text.Length)
  21. {
  22. matchedString = text.Substring(i, length);
  23. }
  24. else
  25. {
  26. matchedString = text.Substring(i);
  27. }
  28.  
  29. Console.WriteLine(matchedString);
  30. i += jump;
  31. }
  32. }
  33. if (!hasMatch)
  34. {
  35. Console.WriteLine("no");
  36. }
  37. }
  38. }
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement