Reputation: 1
C:\Users\asus\AppData\Local\Temporary Projects\ConsoleApplication1\bin\Release\sfref.txt
How to split string to get only sfref.txt
Upvotes: 0
Views: 1569
Reputation: 30698
new FileInfo(@"C:\Users\asus\AppData\Local\Temporary Projects\ConsoleApplication1\bin\Release\sfref.txt").Name
Upvotes: 0
Reputation: 236228
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;
Upvotes: 3
Reputation: 26143
You don't need regex...
System.IO.Path.GetFilename(fullpath);
Upvotes: 5