[Original] filter Request Parameters

Source: Internet
Author: User

Can we use the system. Web. httpcontext. Current. Request. url. query. split method to obtain such a character? Name = caicaihui & Title = hahaha & page = 1

If we want to filter out one of the parameters, for example, filter out the page parameter to get the final result? Name = caicaihui & Title = hahaha what should I do? Here I have written three methods for your reference.

Method 1 use Arrays

Private   String Outrequest1 ( String Request)
{
String Query =   "" ;
String [] Para = System. Web. httpcontext. Current. Request. url. query. Split ( " ? & " . Tochararray ());
Foreach ( String Name In Para)
{
If ( ! Name. tolower (). Contains (request ))
{
Query + =   " & "   + Name;
}
}
Return   " ? "   + Query. trimstart ( ' & ' );
}

CallOutrequest1 ("Page")

Method 2 traverse request
Private   String Outrequest2 ( String Request)
{
String Query =   "" ;
Foreach ( String Name In Request. querystring. allkeys)
{
If (Name. tolower () ! = Request)
{
Query + =   " & "   + Name +   " = "   + Request. querystring [name];
}
}
Return   " ? "   + Query. trimstart ( ' & ' );
}

CallOutrequest2 ("Page")

Method 3 use regular expressions

Private   String Outrequest3 ( String Request)
{
Return RegEx. Replace (system. Web. httpcontext. Current. Request. url. query, request, "" );
}

CallOutrequest3 (@ "[& | \?] Page = \ D +")

CodeAspect:In the three methods, regular code is the simplest, but also difficult. Second, it is method 2, which is easy to understand.

Efficiency:Method 2> method 3> method 1

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.