Saturday, December 29, 2007

C#: Logical equivalent of Request.QueryString

public string SearchQueryString(string queryString, string key)
{
string response = null;
if (queryString.Length > 0 && queryString.Contains(key))
{
queryString = queryString.Substring(1, queryString.Length - 1);
for (int i = 0; i < queryString.Split('&').Length; i++)
{
string subQuery = queryString.Split('&')[i];
string subQueryKey = subQuery.Split('=')[0];
string subQueryValue = subQuery.Split('=')[1];
if (subQueryKey.ToLower() == key.ToLower())
return subQueryValue;
}
}
return response;
}

No comments:

Post a Comment

Please use your common sense before making a comment, and I truly appreciate your constructive criticisms.