1

I have looked at the split string methods in C#, such as:

string[] lines = Regex.Split(value, "\");

Although I have come across the situation where I need to extract a file name from a file path, so I dont want to have to split the string on all occurrences of "\" e.g.:

C:\Windows\System32\calc.exe

Expected output:

calc.exe
4

2 回答 2

5
new FileInfo(@"C:\Windows\System32\calc.exe").Name
于 2012-04-13T08:10:30.793 回答
4

Let the framework take the strain. Use the Path.GetFilename method.

http://msdn.microsoft.com/en-us/library/system.io.path.getfilename.aspx

于 2012-04-13T08:12:02.973 回答