Click here to Skip to main content
15,889,867 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
my querystring is: id=571551&locationId=22&pg=1&ln=1
and i want to extract only id=571551 and my result should be: locationId=22&pg=1&ln=1.how can i do this
Posted
Comments
Suvendu Shekhar Giri 30-Dec-14 2:37am    
Where you need these values? Can you just describe a little more about your problem.

C#
string q = @"id=571551&locationId=22&pg=1&ln=1";

string q2 = q.Substring(q.IndexOf("&") + 1);
 
Share this answer
 
Comments
Agent__007 30-Dec-14 6:09am    
+5ed!
[no name] 31-Dec-14 0:17am    
This will always gove the first querystring. For subsequent querystrings it will not work. For that my ans below will work. still it resolves the issue of the person who had asked the question.
Hi,

Here you can see the query string is having a querystring separator "&" Use the split function to separate the parameters based on the deliminator (&) and it will result you the parameters in an array. then you can skip the required parameters from the array and reform the querystring using stringbuilder.

Thanks
Sisir Patro
 
Share this answer
 
Comments
Member 9361273 30-Dec-14 4:20am    
Thanks Sisir Patro i did it but in this way i cannot findout absolute solution.in this way my result is: division=Dhaka&pg=1&keyword=bba&ln=1& where an extra deliminator has added in string. my code is:
querystring = id=571889&division=Dhaka&pg=1&keyword=bba&ln=1;
string[] arr = querystring.Split('&');
var items1 = arr.Skip(1);
StringBuilder surl = new StringBuilder();
foreach (String s in items1)
{
surl.Append(s + "&");
}
[no name] 30-Dec-14 5:04am    
As you have a requirement that you want to remove the 1st query string only right.
Then you can get the querystring value as mentioned above. Now your value will be "id=571889". Keep this value in a variable and append "&" at the end. Now your value becomes "id=571889&". Now using string.Replace() method you can replace this value with "".

Thanks
Member 9361273 31-Dec-14 0:05am    
thanks sisir.i solved my problem.
[no name] 31-Dec-14 0:09am    
Cool.
you can easily get you desire querystring use:
C#
Request.QueryString["ID"] 
and use it where needed separately.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900