这看起来非常简单,但我尝试的一切似乎都不起作用
假设我有以下字符串:
string myString = "http://www.mysite.com/folder/file.jpg";
我该如何处理它以删除 URL 并仅保留“file.jpg”作为字符串值?
Thanks!
Kris
您可以随时使用System.IO.Path http://msdn.microsoft.com/en-us/library/system.io.path.aspx methods
string myString = "http://www.mysite.com/folder/file.jpg";
string fileName = Path.GetFileName(myString); // file.jpg
如果你确实想处理更复杂的 URI,你可以通过它System.Uri http://msdn.microsoft.com/en-us/library/system.uri.aspx输入并获取绝对路径
string myString = "http://www.mysite.com/folder/file.jpg?test=1";
Uri uri = new Uri(myString);
string file = Path.GetFileName(uri.AbsolutePath);
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)