I have a completed string like this
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:
this string is like this
I need to extract the values for Key "RGI" and "N".
I can do it via for loop , I want a efficient way to do this. any help on this.
Edit: from ~ ~ To ~~
Don't know if it's more efficient than RegEx, but here's a alternative using LINQ to Objects.
KeyValuePair<string, string>[] ns = (from po in pos.Split(new string[] { "~~" }, StringSplitOptions.RemoveEmptyEntries)
from op in po.Split(new string[] { "++" }, StringSplitOptions.RemoveEmptyEntries)
where op.StartsWith("N:") || op.StartsWith("RGI:")
let op_split = op.Split(':')
select new KeyValuePair<string, string>(op_split[0], op_split[1])).ToArray();
I think you should try a regular expression. Since you are using C#, check out this handy .NET RegEx cheat sheet.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With