Get url parameters from a string in .NET

前端 未结 13 1779
一个人的身影
一个人的身影 2020-11-22 11:38

I\'ve got a string in .NET which is actually a url. I want an easy way to get the value from a particular parameter.

Normally, I\'d just use Request.Params[

13条回答
  •  孤独总比滥情好
    2020-11-22 11:54

    For anyone who wants to loop through all query strings from a string

            foreach (var item in new Uri(urlString).Query.TrimStart('?').Split('&'))
            {
                var subStrings = item.Split('=');
    
                var key = subStrings[0];
                var value = subStrings[1];
    
                // do something with values
            }
    

提交回复
热议问题