using System.Collections.Generic;
using System.Text.RegularExpressions;
static void Main(string[] args)
Dictionary<string, string> dict = new Dictionary<string, string>
string previouslyString = " ZLKMVBEJbb CCCCDDD ddDD";
var processing = new ProcessingRight();
string result = processing.Run(previouslyString, dict);
Console.WriteLine(result);
public class ProcessingRight
public string Run(string input, Dictionary<string, string> inputDict)
var resultList = new List<string>();
char[] array = input.ToArray();
string prevSymbols = string.Empty;
for (int i = 0; i < array.Length; i++)
string replaceValue = GetReplaceValue(input, inputDict, array[i], ref i);
resultList.Add(replaceValue);
string result = string.Join("", resultList.ToArray());
private string GetReplaceValue(string input, Dictionary<string, string> inputDict, char current, ref int index)
string currentStr = current.ToString();
string pattern = string.Format(@"^{0}", currentStr);
foreach (var item in inputDict)
string template = item.Key;
bool isMatch = Regex.IsMatch(template, pattern);
if (index + template.Length > input.Length)
string piece = input.Substring(index, template.Length);
index = index + template.Length - 1;