Advertisement
martinvalchev

Substring

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