How to Get URL Parameters from String in C# ?

Assume that you have a string that contains the URL and you want to get the parameters from it in C#, You can easily do it using the static ParseQueryString method that is defined in the System.Web.HttpUtility namespace.

How to Get URL Parameters from String in C# ?

Below is a sample code snippet that demonstrates how you can retreive the URL parameters from a C# string/

Uri myUri = new Uri("http://www.coderseditor.com?param1=tutorial&param2=onlineide");
string param1 = HttpUtility.ParseQueryString(myUri.Query).Get("param1");

The above code snippet will return the value tutorial and will be assigned to the variable param1.

Share:

Leave A Reply

Your email address will not be published. Required fields are marked *

You May Also Like

C# Compiler Error CS0442 – ‘Property’: abstract properties cannot have private accessors Reason for the Error You’ll get this error...
This is a really simple one . Below is a simple example of an enum called “Designation” defined with the...
This blog post explain the usage of the Checked Block in .NET and how you can use them in Visual...