开发者

find the matching word C#

开发者 https://www.devze.com 2023-03-06 21:09 出处:网络
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#?
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

精彩评论

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

关注公众号