I'm new to C#, and thus am looking for layman's terms regarding this. Essentially, what I would like to do is turn:
key1=val1|key2=val2|...|keyN=valN
into a database array where, you guessed it, key1 returns val1, key2 returns val2, etc. I know I could return a string using split, but from that point on, I'm at a loss. Any help would be greatly appreciated! I hope I've made my intentions clear, but if you have any questions, don't hesitate to ask!
string s = "key1=val1|key2=val2|keyN=valN";
var dict = s.Split('|')
.Select(x => x.Split('='))
.ToDictionary(x => x[0], x => x[1]);
Now dict
is a Dictionary<string, string>
with the desired key/value pairs.
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