开发者

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.


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


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


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

url.Substring(38, 14);


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜