MiroslavKisov

AnonymousVox

Nov 14th, 2017
175
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.39 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Text.RegularExpressions;
  6. using System.Threading.Tasks;
  7.  
  8. namespace _03.AnonymousVox
  9. {
  10.     public class StartUp
  11.     {
  12.         public static void Main()
  13.         {
  14.             string input = Console.ReadLine();
  15.             string placeholder = Console.ReadLine();
  16.             string inputPattern = @"([a-zA-Z]+)(.+)\1";
  17.             string result = string.Empty;
  18.             var placeholderCollection = placeholder.Split(new char[] { '{', '}' }, StringSplitOptions.RemoveEmptyEntries);
  19.             Regex inputRegex = new Regex(inputPattern);
  20.             MatchCollection matches = inputRegex.Matches(input);
  21.             int index = 0;
  22.             foreach (Match match in matches)
  23.             {
  24.                 if (index >= placeholderCollection.Length)
  25.                 {
  26.                     break;
  27.                 }
  28.                 string oldValue = match.Groups[2].ToString();
  29.                 string newValue = placeholderCollection[index++];
  30.                 string oldValueSubstring = input.Substring(0, input.IndexOf(oldValue) + oldValue.Length);
  31.                 string newValueSubstring = oldValueSubstring.Replace(oldValue, newValue);
  32.                 input = newValueSubstring + input.Substring(oldValueSubstring.Length);
  33.             }
  34.             Console.WriteLine(input);
  35.         }
  36.     }
  37. }
Advertisement
Add Comment
Please, Sign In to add comment