Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Text.RegularExpressions;
- using System.Threading.Tasks;
- namespace _03.AnonymousVox
- {
- public class StartUp
- {
- public static void Main()
- {
- string input = Console.ReadLine();
- string placeholder = Console.ReadLine();
- string inputPattern = @"([a-zA-Z]+)(.+)\1";
- string result = string.Empty;
- var placeholderCollection = placeholder.Split(new char[] { '{', '}' }, StringSplitOptions.RemoveEmptyEntries);
- Regex inputRegex = new Regex(inputPattern);
- MatchCollection matches = inputRegex.Matches(input);
- int index = 0;
- foreach (Match match in matches)
- {
- if (index >= placeholderCollection.Length)
- {
- break;
- }
- string oldValue = match.Groups[2].ToString();
- string newValue = placeholderCollection[index++];
- string oldValueSubstring = input.Substring(0, input.IndexOf(oldValue) + oldValue.Length);
- string newValueSubstring = oldValueSubstring.Replace(oldValue, newValue);
- input = newValueSubstring + input.Substring(oldValueSubstring.Length);
- }
- Console.WriteLine(input);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment