C # parsing URL parameters and getting a list of parameter and value corresponding methods

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.