MiroslavKisov

Substring

Oct 6th, 2017
166
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.99 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.         string result = string.Empty;
  9.         int jump = int.Parse(Console.ReadLine());
  10.         int symbol = 112;
  11.         bool hasMatch = false;
  12.         for (int i = 0; i < text.Length; i++)
  13.         {
  14.             int step = jump;
  15.             if (text[i] == symbol)
  16.             {
  17.                 hasMatch = true;
  18.                 while (true)
  19.                 {
  20.                     try
  21.                     {
  22.                         result = text.Substring(i, step+ 1);
  23.                         i += jump;
  24.                         Console.WriteLine(result);
  25.                         break;
  26.                     }
  27.                     catch (Exception ex)
  28.                     {
  29.                         step--;
  30.                     }
  31.                 }
  32.             }
  33.         }
  34.         if (!hasMatch)
  35.         {
  36.             Console.WriteLine("no");
  37.         }
  38.     }
  39. }
Advertisement
Add Comment
Please, Sign In to add comment