user761318
user761318

Reputation: 13

find the matching word C#

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.

Upvotes: 1

Views: 133

Answers (4)

codymanix
codymanix

Reputation: 29540

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

Upvotes: 0

Jason
Jason

Reputation: 89214

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);
}

Upvotes: 1

Alex K.
Alex K.

Reputation: 175956

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 /)

Upvotes: 1

Kyle Sletten
Kyle Sletten

Reputation: 5413

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

url.Substring(38, 14);

Upvotes: 0

Related Questions