Ian*_*erg 3 c# string substring
我试图在URL的末尾提取字符串.例:
C:\this\that\ExtractThisString.exe
^^^^^^^^^^^^^^^^^^^^^
Run Code Online (Sandbox Code Playgroud)
我试图ExtractThisString.exe从那个字符串中获取,但它有一个未知数量\的.我希望它基本上抓住URL并列出最后的内容.
使用System.IO.Path类的帮助方法.在你的情况下:
string fileName = Path.GetFileName(@"C:\this\that\ExtractThisString.exe");
Run Code Online (Sandbox Code Playgroud)
只是为了好玩,如果你必须自己创建,你应该开始搜索最后一个Path.DirectorySeparatorChar的索引.如果那不是字符串中的最后一个字符,那么您可以使用它String.Substring来提取该索引之后的所有文本.