The example in this article describes the method by which C # parses the URL parameter to get the parameter and value corresponding list. Share to everyone for your reference. The specific analysis is as follows:
This C # function is used to parse all parameters passed in the URL, to output a namevaluecollection list of parameter names and parameter values, which can often be used
<summary>///parsing the parameter information in the URL string///</summary>///<param name= "url" > Input url</param>///< param name= "BASEURL" > The base part of the output URL </param>///<param name= "NVC" > Output analysis (parameter name, parameter value) collection </param> public static void parseURL (string url, out string baseUrl, out NameValueCollection NVC) { if (url = = null) throw new A Rgumentnullexception ("url"); NVC = new NameValueCollection (); BASEURL = ""; if (url = = "") return; int questionmarkindex = URL. IndexOf ('? '); if (Questionmarkindex = =-1) {baseUrl = URL; return; } BASEURL = URL. Substring (0, questionmarkindex); if (questionmarkindex = = URL. LENGTH-1) return; string ps = URL. Substring (Questionmarkindex + 1); Start parsing parameters to regex re = new regex (@ "(^|&)?" ( \w+) = ([^&]+) (&|$)? ", regexoptions.compiled); MatchCollection mc = Re. Matches (PS); foreach (Match m in MC) {NVC. ADD (M.result ("$"). ToLower (), M.result ("$");} }
I hope this article is helpful to everyone's C # programming.
In addition to the Declaration,
Running GuestArticles are original, reproduced please link to the form of the address of this article
C # parsing URL parameters and getting a list of parameter and value corresponding methods
This address: http://www.paobuke.com/develop/c-develop/pbk23058.html
Related content The scrolling-related requirements in the ListView usage implementation of C # format JSON string method Analysis C # Implementation of several database large data bulk inserts parsing the application of assertions and exceptions in C # and process Control of exception handling
C # Regular expression Regex class common match in C # to determine whether a class implements an interface in C # the tomato clock countdown timer Code C # implement PropertyGrid custom properties
C # parsing URL parameters and getting a list of parameter and value corresponding methods