java - How to parse the string into map -
have string a=b&c=d&e=f, how parse map?
i use split
string text = "a=b&c=d&e=f"; map<string, string> map = new linkedhashmap<string, string>(); for(string keyvalue : text.split(" *& *")) { string[] pairs = keyvalue.split(" *= *", 2); map.put(pairs[0], pairs.length == 1 ? "" : pairs[1]); }
edit allows padded spaces , value =
or no value. e.g.
a = minus- & c=equals= & e==f
Comments
Post a Comment