Q
獲取內容
17
A
回答
27
string path = "C://hello//world";
int pos = path.LastIndexOf("/") + 1;
Console.WriteLine(path.Substring(pos, path.Length - pos)); // prints "world"
的LastIndexOf
方法執行相同IndexOf
..但是從字符串的結尾。
3
我會建議看看System.IO
命名空間,因爲它似乎你可能想要使用它。還有DirectoryInfo和FileInfo也可以在這裏使用。具體DirectoryInfo's Name property
var directoryName = new DirectoryInfo(path).Name;
9
9
using System.Linq;
var s = "C://hello//world";
var last = s.Split('/').Last();
1
試試這個:
string worldWithPath = "C://hello//world";
string world = worldWithPath.Substring(worldWithPath.LastIndexOf("/") + 1);
相關問題
- 1. 獲取JSON內容
- 2. 獲取jar內容
- 3. 如何獲取href內容
- 4. Python獲取內容長度
- 5. java:獲取html內容
- 6. 獲取WP Tinymce的內容
- 7. 從塊中獲取內容
- 8. 獲取SimpleXMLElement的XML內容
- 9. 從jquery獲取內容CLEditor
- 10. QWebView獲取內容類型
- 11. framelayout如何獲取內容?
- 12. 從JSPWriter獲取內容
- 13. 文件獲取內容PHP
- 14. 獲取內容:新行
- 15. Java RTSP獲取內容
- 16. jQuery:獲取內容/ innerhtml onclick
- 17. PHP獲取URL內容
- 18. jQuery的:獲取父內容
- 19. 如何獲取內容?
- 20. 獲取webservice的內容
- 21. 獲取段落內容
- 22. Symbian獲取內容類型?
- 23. 獲取GVariant的內容
- 24. Spreadsheet_Excel_Writer獲取文件內容
- 25. 獲取iframe的內容
- 26. 無法獲取httpResponse內容
- 27. 從DIV內容獲取SRC
- 28. 獲取HTML內容提交
- 29. Ajax無法獲取內容
- 30. 獲取文件內容
我曾經想過,但要注意的是,OP似乎不把重點放在一個文件,而是一個目錄 – 2013-04-07 02:51:23