using System.Collections.Generic;
public static class Program
public static void Main()
string source = "'<lookup><entity>a</entity><filter>1,2,3</filter></lookup>'Please select the type of U.S person you ar<lookup><entity>b</entity><filter>4,5,6</filter></lookup> nds with your Federal income t<lookup><entity>c</entity><filter>7,8</filter></lookup> ,{'";
var ServicesExecutionDic = ExtractLookUpAsDictionary(source);
foreach(var a in ServicesExecutionDic){
public static Dictionary<Tuple<string, string>, List<int>> ExtractLookUpAsDictionary(string source)
var result = new Dictionary<Tuple<string, string>, List<int>>();
int[] indexes = source.AllIndexesOf("<lookup>").ToArray();
foreach (int index in indexes)
var tag = source.Substring(index).GetBetween("<lookup>", "</lookup>");
var entity = tag.GetBetween("<entity>", "</entity>");
var filter = tag.GetBetween("<filter>", "</filter>");
var TupleKey = Tuple.Create(entity, filter);
if (!result.TryAdd(TupleKey, new List<int> { index }))
result[TupleKey].Add(index);
public static IEnumerable<int> AllIndexesOf(this string source, string searchstring)
int minIndex = source.IndexOf(searchstring);
minIndex = source.IndexOf(searchstring, minIndex + searchstring.Length);
public static string GetBetween(this string source, string before, string after)
int beforeStartIndex = source.IndexOf(before);
int startIndex = beforeStartIndex + before.Length;
int afterStartIndex = source.IndexOf(after, startIndex);
if (beforeStartIndex == -1 || afterStartIndex == -1)
return source.Substring(startIndex, afterStartIndex - startIndex);