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