// Collection of code snippets by Arne Vajhøj // (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) using System; using System.Collections.Specialized; class MainClass { public static NameValueCollection Parse(string s) { NameValueCollection res = new NameValueCollection(); string[] parts = s.Split("=&".ToCharArray()); for(int i = 0; i < parts.Length/2; i++) { res.Add(parts[2*i], parts[2*i+1]); } return res; } public static void Main(string[] args) { NameValueCollection col = Parse("k1=v1&k2=v2&k3=v3"); for(int i = 0; i < col.Count; i++) { Console.WriteLine(col.GetKey(i) + " = " + col.GetValues(i)[0]); } } }