简体   繁体   中英

How to get base filename without query portion?

Given a file path URL such as http://example.com/video.flv?start=5 , I want to get out video.flv .

Path.GetFileName("http://example.com/video.flv?start=5") yields video.flv?start=5 , which is more than I want. I can't find anything relevant in the Uri class either. Am I missing something?

多种方法,但只有一种选择:

new Uri("http://example.com/video.flv?start=5").Segments.Last()

Using Uri.AbsolutePath I was able to achieve the desired results.

Uri t = new Uri("http://example.com/video.flv?start=5");
Console.WriteLine(t.AbsolutePath);
Console.ReadLine();

printed /video.flv

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM