Advertisement
EmoRz

Anonymous_Vox

Apr 18th, 2018
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.13 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text.RegularExpressions;
  5. namespace Exercise
  6. {
  7.     class Program
  8.     {
  9.         static void Main(string[] args)
  10.         {
  11.             var placeholder = Console.ReadLine();
  12.             var regPlace = @"([A-Za-z]+)(.+)\1";
  13.             var value = Console.ReadLine();
  14.             var regValue = @"({)(.*?)(})";
  15.             //
  16.             MatchCollection placeholderCollection = Regex.Matches(placeholder,regPlace);
  17.             MatchCollection valueCollection = Regex.Matches(value, regValue);
  18.             //
  19.  
  20.             for (int i = 0; i < Math.Min(placeholderCollection.Count, valueCollection.Count); i++)
  21.             {
  22.                 string toChange = placeholderCollection[i].Groups[2].Value;
  23.                 string toPut = valueCollection[i].Groups[2].Value;
  24.                 int index = placeholder.IndexOf(toChange);
  25.                 placeholder = placeholder.Remove(index, toChange.Count());
  26.                 placeholder = placeholder.Insert(index, toPut);
  27.             }
  28.             Console.WriteLine(placeholder);
  29.            
  30.         }
  31.     }
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement