GerganaTsirkova

AnonymousVox

Feb 28th, 2018
182
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.95 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3. using System.Text.RegularExpressions;
  4.  
  5. namespace _2.AnonimousVox
  6. {
  7.     class Program
  8.     {
  9.         static void Main(string[] args)
  10.         {
  11.             string textToEncode = Console.ReadLine();
  12.             string[] values = Console.ReadLine()
  13.                 .Split(new char[] { '{', '}'},StringSplitOptions.RemoveEmptyEntries )
  14.                 .ToArray();
  15.             string pattern = @"([A-Za-z]+)(.+)\1";
  16.             Regex regex = new Regex(pattern);
  17.             MatchCollection matches = regex.Matches(textToEncode);
  18.             int valueIndex = 0;
  19.             foreach (Match match in matches)
  20.             {
  21.                 if(valueIndex >= values.Length)
  22.                 {
  23.                     break;
  24.                 }
  25.                 string result = Regex.Replace(textToEncode, match.Groups[2].Value, values[valueIndex++]);
  26.                 Console.WriteLine(result);
  27.             }
  28.         }
  29.     }
  30. }
Advertisement
Add Comment
Please, Sign In to add comment