Advertisement
Guest User

Untitled

a guest
Apr 10th, 2019
175
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.36 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text.RegularExpressions;
  4.  
  5. namespace _03._Anonymous_Vox
  6. {
  7.     class Program
  8.     {
  9.         static void Main(string[] args)
  10.         {
  11.             string input = Console.ReadLine();
  12.            
  13.             char[] separator = { '{', '}' };
  14.             string pattern = @"(?<start>[A-Za-z]+)(?<placeholder>.+)\1";
  15.             MatchCollection matches = Regex.Matches(input,pattern);
  16.             List<string> strList = new List<string>();
  17.             string[] values = Console.ReadLine().Split(new[] {'{','}'},StringSplitOptions.RemoveEmptyEntries);
  18.             foreach (Match match in matches)
  19.             {
  20.                 string placeholder = match.Groups["placeholder"].Value;
  21.                 strList.Add(placeholder);
  22.  
  23.             }
  24.             int end = Math.Min(values.Length,strList.Count);
  25.  
  26.             for (int i = 0; i < end; i++)
  27.             {
  28.                 input = ReplaceFirstOccurance(input,strList[i],values[i]);
  29.             }
  30.             Console.WriteLine(input);
  31.         }
  32.  
  33.         private static string ReplaceFirstOccurance(string input, string match, string replace)
  34.         {
  35.             int index = input.IndexOf(match);
  36.             input = input.Remove(index,match.Length);
  37.             input = input.Insert(index,replace);
  38.             return input;
  39.         }
  40.     }
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement