1
http://www.vkeong.com/2008/food-drink/nasi-lemak-wai-sik-kai-kepong-baru/ 

Hi, how to get the 'nasi-lemak-wai-sik-kai-kepong-baru' from this hyperlink using C#?

Thanks.

1
  • 1
    This gets you what you want: string result = "nasi-lemak-wai-sik-kai-kepong-baru" :D Commented May 19, 2011 at 16:05

4 Answers 4

1

How about;

var uri = new System.Uri("http://www.vkeong.com/2008/food-drink/nasi-lemak-wai-sik-kai-kepong-baru/"); string dir = new System.IO.FileInfo(uri.LocalPath).Directory.Name; 

(This would return 2008 were there no terminating /)

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

Comments

1

Use the Segments property of the URI class

URI uri = new URI("http://www.example.com/alpha/beta/gamma"); foreach(string s in uri.Segments) { Console.Writeline(s); } 

1 Comment

Nice! This is a much better answer than mine. Can you please post some code for the OP though... There seems to be an issue with the trailing / though
0

For that specific string I'd use the String.Substring(int offset, int length) method.

url.Substring(38, 14); 

1 Comment

You're probably right, but that is how he phrased the question.
0

Trim the last /, then find the index of the now last / and make a substring from this found idnex to the end.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.