在.NET 4.0中,urls的IO.Path.GetFileName
等效函數是什麼?urls的IO.Path.GetFileName的等價函數?
8
A
回答
13
Uri
班是你的朋友。
提供統一資源標識符(URI)的對象表示形式,並可輕鬆訪問URI的各個部分。
IsFile
將嘗試確定Uri
確實指向一個文件。
使用Segements
屬性,以獲取文件名(這將是最後一段)。
Uri uri = new Uri("http://example.com/title/index.htm");
var filename = uri.Segments[uri.Segments.Length - 1];
// filename == "index.htm"
0
您可以使用Server.MapPath()從虛擬路徑映射物理路徑。
此外,還有許多的HTTPUtility中的方法,可以幫助你繪製各種不同類型的路徑。
0
方法有很多種,主要被描述here
Baqsically如果需要利用Uri類,也許串tokeniztion。
1
您可能會粘在創建開放的對象,如果你關心與此類似性能使用的東西:
public class UriHelpers
{
public static string GetFileNameFromUrl(string url)
{
string lastSegment = url.Split('/').Last();
return lastSegment.Substring(0, lastSegment.IndexOf('?') < 0 ? lastSegment.Length : lastSegment.IndexOf('?'));
}
}
相關問題
- 1. Ruby的等價於PHP的ucfirst()函數
- 2. Python的等價物的MATLAB psf2otf函數
- 3. Ruby的等價PHP的mcrypt_encrypt()函數
- 4. Java中C的「_getch()」的等價函數?
- 5. C++中的fprint的等價函數
- 6. Python的等價於R的logspace_add函數?
- 7. Ruby的等價於PHP的「get_defined_vars」函數?
- 8. Immutable.js和flatMap等價函數
- 9. Dojo等價於jQuery.text函數?
- 10. Cognos等價於excel的sumif()函數
- 11. Python等價於Ruby的包函數
- 12. 「$ .getJSON(」myurl「,response)的等價回調函數;」?
- 13. python中的perror等價函數
- 14. VBA等價於VBScript的'SetLocale'函數?
- 15. OpenCV中的Matlab Bwareaopen等價函數
- 16. 這與TAlphaColor的StringToColor函數等價嗎?
- 17. 什麼是Haskell中的「::」等價函數?
- 18. greenplum中的ISDATE()等價函數
- 19. Application.DoEvents() - >在java中的等價函數?
- 20. Linq等價的SQL LEFT函數?
- 21. .net等價於Delphi的QuotedStr函數
- 22. 是否有GetProperty或等價函數?
- 23. #define是否等價於一個函數?
- 24. ,與javascript real xml函數等價嗎?
- 25. ASP Filter功能 - > C#等價函數
- 26. ASP.NET,等價於PHP Print_r函數?
- 27. 來自R的Stata的「logistic」的任何等價函數?
- 28. 某些(有用的)函數式編程函數(如any(),all())的PHP等價物?
- 29. 函數式編程:等價性和價值評估
- 30. 等價的.send()
感謝/效果很好,除了ISFILE給了我假的這個uriString中:[鏈接](HTTP ://www.example.com/foo/bar/banner/enu_wide_small_219x113_white.gif) – Muleskinner 2012-03-01 15:59:22
isFile將只返回true,如果url的格式爲file:// – Lukos 2018-01-02 15:17:48