using System.Collections.Generic;
public static void Main()
string inputString = "sdfgabcwetrrytruyrtuabcpotre!@#abcprtort";
var resultList = new List< Dictionary<string,string>>();
resultList.Add(Program.processString(inputString,"abc"));
resultList.Add(Program.processString(inputString,"s"));
resultList.Add(Program.processString(inputString,"r"));
resultList.Add(Program.processString(inputString,"zi"));
public static Dictionary<string, string> processString(String inputStr, String separator)
Dictionary<string, string> result = new Dictionary<string, string>();
result.Add("Count", GetCount(inputStr, separator));
result.Add("Prefix", GetPrefix(inputStr, separator));
result.Add("sortedItems", GetSortedItems(inputStr, separator));
result.Add("evenChars", GetEvenChars(inputStr, separator));
private static string GetEvenChars(string inputStr, string separator)
foreach (char input in inputStr)
private static string GetSortedItems(string inputStr, string separator)
string order = string.Empty;
var items = new Dictionary<int, char>();
foreach (char inputChar in inputStr)
if (items.ContainsValue(inputChar)) continue;
items.Add(((byte)inputChar), inputChar);
var orderList = items.OrderByDescending(o => o.Key);
foreach (var orderItem in orderList)
order += (orderItem.Value);
private static string GetPrefix(string inputStr, string separator)
int index = inputStr.IndexOf(separator);
return index > 0 ? inputStr.Substring(0, index) : inputStr;
private static string GetCount(String inputStr, String separator)
int index = inputStr.IndexOf(separator);
inputStr = inputStr.Substring(index + separator.Length);
if (index == 0 || inputStr.Count() < separator.Count()) break;