kirililchev3

Debug Substring

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