extract query string from a URL string

后端 未结 8 1510
抹茶落季
抹茶落季 2021-01-04 04:10

I am reading from history, and I want that when i come across a google query, I can extract the query string. I am not using request or httputility since i am simply parsing

8条回答
  •  抹茶落季
    2021-01-04 04:32

    here is the solution -

    string GetQueryString(string url, string key)
    {
        string query_string = string.Empty;
    
        var uri = new Uri(url);
        var newQueryString = HttpUtility.ParseQueryString(uri.Query);
        query_string = newQueryString[key].ToString();
    
        return query_string;
    }
    

提交回复
热议问题