Advertisement
DaniPasteBin

Untitled

Jun 26th, 2018
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.06 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text.RegularExpressions;
  5.  
  6. namespace _03.CameraView
  7. {
  8.     class Program
  9.     {
  10.         static void Main(string[] args)
  11.         {
  12.             int[] numbers = Console.ReadLine().Split().Select(int.Parse).ToArray();
  13.             int m = numbers[0];  //skip
  14.             int n = numbers[1];  //take
  15.  
  16.             string input = Console.ReadLine();
  17.             //string pattern = $@"\|< ([\w]{m})([\w]{ 0,{n}})";
  18.             string pattern = @"\|<([\w]{" + m + @"})([\w]{0,"+ n + @"})"; //още един начин да се вмъкне променлива в regex
  19.  
  20.             MatchCollection myMatches = Regex.Matches(input, pattern);
  21.  
  22.             List<string> result = new List<string>();
  23.             foreach (Match myM in myMatches)
  24.             {
  25.                 result.Add(myM.Groups[2].Value);  //тук броенето е от 1. Патерна е разделен на групи от ()
  26.             }
  27.             Console.WriteLine(string.Join(", ",result));
  28.         }
  29.     }
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement