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.
精彩评论