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

This C# program calculates and displays an upper triangular matrix based on user input. Problem Statement: The program takes the...
This C# program serves as a demonstration of bitwise operators, which are fundamental operators used for manipulating individual bits in...
This C# program is designed to interchange or swap the columns of a matrix. A matrix is a two-dimensional array...