Advertisement
Guest User

Anonymous Vox

a guest
Nov 6th, 2017
510
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.24 KB | None | 0 0
  1. namespace task03
  2. {
  3.     using System;
  4.     using System.Linq;
  5.     using System.Text.RegularExpressions;
  6.  
  7.     public class StartUp
  8.     {
  9.         public static void Main()
  10.         {
  11.             string input = Console.ReadLine();
  12.  
  13.             string[] values = Console.ReadLine()
  14.                             .Trim()
  15.                             .Split(new string[] { "{", "}" }, StringSplitOptions
  16.                             .RemoveEmptyEntries)
  17.                             .ToArray();
  18.  
  19.             string pattern = @"([a-zA-Z]+)(.+)(\1)";
  20.  
  21.             Regex reg = new Regex(pattern);
  22.  
  23.             int index = 0;
  24.  
  25.             foreach (Match item in reg.Matches(input))
  26.             {
  27.                 if (index < values.Length)
  28.                 {
  29.                     string currentValue = values[index];
  30.  
  31.                     int startIndex = input.IndexOf(item.Groups[2].ToString());
  32.                     int length = item.Groups[2].Length;
  33.  
  34.                     input = input.Remove(startIndex, length).Insert(startIndex, currentValue);
  35.  
  36.                     //input = reg.Replace(input, item.Groups[2].Value, 1, 0 );
  37.                 }
  38.  
  39.                 index++;
  40.             }
  41.  
  42.             Console.WriteLine(input);
  43.         }
  44.     }
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement