I\'m having a string like
\"List_1 fooo asdf List_2 bar fdsa XList_3 fooo bar\"
and a List
like
You can use following code achieving this task
string str = "List_1 fooo asdf List_2 bar fdsa XList_3 fooo bar";
List l_lstValues = new List { "List_1", "XList_3", "List_2" };
string[] strarr = str.Split(' ');
string sKey, sValue;
bool bFlag = false;
sKey = sValue = string.Empty;
var lstResult = new List>();
foreach (string strTempKeys in l_lstValues)
{
bFlag = false;
sKey = strTempKeys;
sValue = string.Empty;
foreach (string strTempValue in strarr)
{
if (bFlag)
{
if (strTempValue != sKey && l_lstValues.Contains(strTempValue))
{
bFlag = false;
break;
}
else
sValue += strTempValue;
}
else if (strTempValue == sKey)
bFlag = true;
}
lstResult.Add(new KeyValuePair(sKey, sValue));
}