0

I have a URL like : http://localhost.com/Dometic-Tou/french-with-flights-milano-10-12-may-2014.html

How can ı get this text from the URL : Domestic-Tou

I have got the link but all I want just Domestic-Tou from the link

I have tried:

Request.Path.Substring(Request.Path.LastIndexOf("/") + 1);

1 Answer 1

2

Don't use Request.substring. It will not give the expected result which you require. Instead use this.

string [] test = link.Split('/');

string required_subpart = test[3].ToString(); 

Note: the index is 3 here. Why because the url contains http://. So if you do not have http:// in your url, the index would be 1. Substitute it with whatever part you want in a url.

Let me know if this works for you, or I have an alternate solution for you.

Sign up to request clarification or add additional context in comments.

4 Comments

I cant do it with this way , I want to second alternative solution thx
I have done with this answer thx , I wonder the second alternative solition ? could you tell me ?
Please up vote the answer if its right. I will share the alternate solution shortly. Are you getting the url from Request.URL paramater?
I voted up but it give to me this error Vote Up requires 15 reputation - Yes , get the url by HttpContext.Current.Request.Url.AbsoluteUri.ToString();

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.