STORM STORM -4 years ago 121
C# Question

How to get a part of a string (url)?

I have the following url

I need to extract the
portion of the url parameter:


This can be in the middle or at the end of the url. I cannot guarantee the position of it. But i always starts with
and end with
. The string between this is what i want. How can i grab this within C#?

Answer Source

You may need to create a Uri and pass the value of its Query property to the HttpUtility.ParseQueryString method:

string value = HttpUtility.ParseQueryString(new Uri("").Query)["Proj"];

The method is defined in System.Web.dll by the way so you need to add a reference to this one.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download