Getting the parent name of a URI/URL from absolute name C#

后端 未结 10 881
失恋的感觉
失恋的感觉 2021-02-04 01:29

Given an absolute URI/URL, I want to get a URI/URL which doesn\'t contain the leaf portion. For example: given http://foo.com/bar/baz.html, I should get http://foo.com/bar/.

10条回答
  •  刺人心
    刺人心 (楼主)
    2021-02-04 02:23

    Quick and dirty

    int pos = uriString.LastIndexOf('/');
    if (pos > 0) { uriString = uriString.Substring(0, pos); } 
    

提交回复
热议问题