You can use this custom function... quick test show that with the string you originally gave in the question it returns the desired output which is two items, one with key sub and value fs&&&FASh*5 and another with key workarea and value London+&Home+Counties+Ltd.
public Dictionary<string, string> ParseQueryString(string qs)
{
Dictionary<string, string> items = new Dictionary<string, string>();
string valueBuffer = string.Empty;
string keyBuffer = string.Empty;
bool lookingForValue = true;
for (int i = qs.Length - 1; i >= 0; i--)
{
char curChar = qs[i];
if (curChar.Equals('='))
{
lookingForValue = false;
keyBuffer = string.Empty;
}
else if (curChar.Equals('&') && !lookingForValue)
{
items.Add(keyBuffer, valueBuffer);
valueBuffer = string.Empty;
lookingForValue = true;
}
else if (curChar.Equals('?'))
{
if (keyBuffer.Length > 0)
items.Add(keyBuffer, valueBuffer);
break;
}
else
{
if (lookingForValue)
valueBuffer = curChar + valueBuffer;
else
keyBuffer = curChar + keyBuffer;
}
}
return items;
}
As I told in the comment, if used for real querystring use Server.URLEncode to encode each value.
Quick explanation: instead of parsing the query string according to & which can't be done, it's looking for = characters, when found start looking for & that appear before.
Server.URLEncodeto encode each value..ParseQueryStringis the best option.?name=black&whiteis valid, but doesn't mean what you want it to mean. Also,+for spaces are grossly outdated. Where did you get this string?