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