Here is an attempt doing a search based on index: (I prefer my LINQ solution that I added)
string test = "N:Pay in Cash++RGI:40++R:200++T:Purchase++IP:N++IS:N++PD:PC++UCP:598.80++UPP:0.00++TCP:598.80++TPP:0.00++QE:1++QS:1++CPC:USD++PPC:Points++D:Y++E:Y++IFE:Y++AD:Y++IR:++MV:++CP:~ ~N:ERedemption++RGI:42++R:200++T:Purchase++IP:N++IS:N++PD:PC++UCP:598.80++UPP:0.00++TCP:598.80++TPP:0.00++QE:1++QS:1++CPC:USD++PPC:Points++D:Y++E:Y++IFE:Y++AD:Y++IR:++MV:++CP:";
string[] parts = test.Split(new string[] { "~ ~" }, StringSplitOptions.None);
var result = parts.Select(p => new
{
N = p.Substring(p.IndexOf("N:") + 2,
p.IndexOf("++") - (p.IndexOf("N:") + 2)),
RGI = p.Substring(p.IndexOf("RGI:") + 4,
p.IndexOf("++", p.IndexOf("RGI:")) - (p.IndexOf("RGI:") + 4))
});
Creates a list of two objects with following values:
result = {{N = "Pay in Cash", RDI = 40}, {N = "ERedemption", RDI = 42}}
EDIT: SOLUTION USING LINQ
I decided to try and do it all with LINQ and here is what I came up with:
string test = "N:Pay in Cash++RGI:40++R:200++T:Purchase++IP:N++IS:N++PD:PC++UCP:598.80++UPP:0.00++TCP:598.80++TPP:0.00++QE:1++QS:1++CPC:USD++PPC:Points++D:Y++E:Y++IFE:Y++AD:Y++IR:++MV:++CP:~ ~N:ERedemption++RGI:42++R:200++T:Purchase++IP:N++IS:N++PD:PC++UCP:598.80++UPP:0.00++TCP:598.80++TPP:0.00++QE:1++QS:1++CPC:USD++PPC:Points++D:Y++E:Y++IFE:Y++AD:Y++IR:++MV:++CP:";
var result = test.Split(new string[] { "~ ~" }, StringSplitOptions.None).
Select(m => m.Split(new string[] { "++" }, StringSplitOptions.None)).
Select(p => p.Select(i => i.Split(':')).
Where(o => o[0].Equals("N") || o[0].Equals("RGI")).
Select(r => new { Key = r[0], Value = r[1]}));
It produces and array for each item that contains a Key Value pair of only N and RGI.
result = {{{Key = "N", Value = "Pay in Cash"}, {Key = "RDI", Value = 40}},
{{Key = "N", Value = "ERedemption"}, {Key = "RDI", Value = 42}}}
If you want you can remove the Where
and it will include all they Keys and their Values.