简体   繁体   中英

To get filename from path Regex

C:\Users\asus\AppData\Local\Temporary Projects\ConsoleApplication1\bin\Release\sfref.txt

如何拆分字符串以仅获取sfref.txt

您不需要正则表达式...

System.IO.Path.GetFilename(fullpath);

Use Path.GetFileName method:

var path = @"C:\Users\asus\AppData\Local\Temporary Projects\ConsoleApplication1\bin\Release\sfref.txt";
string name = Path.GetFileName(path); // sfref.txt

If you really need to do that with regular expressions (what I do not advice to do):

string name = Regex.Match(path, @"[^\\]*$").Value;

You can use FileInfo . Name

new FileInfo(@"C:\Users\asus\AppData\Local\Temporary Projects\ConsoleApplication1\bin\Release\sfref.txt").Name

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM