Breaking News
Loading...
30/09/2013

Path.GetFileName Method in C#

Hôm nay do yêu cầu công việc, tôi cần hàm lấy file name của 1 file từ một full path.

Đây là đoạn mã ví dụ trên MSDN

string fileName = @"C:\mydir\myfile.ext";
string path = @"C:\mydir\";
string result;

result = Path.GetFileName(fileName);
Console.WriteLine("GetFileName('{0}') returns '{1}'", 
    fileName, result);

result = Path.GetFileName(path);
Console.WriteLine("GetFileName('{0}') returns '{1}'", 
    path, result);

// This code produces output similar to the following: 
// 
// GetFileName('C:\mydir\myfile.ext') returns 'myfile.ext' 
// GetFileName('C:\mydir\') returns ''

Đây là document trên MSDN:
http://msdn.microsoft.com/en-us/library/system.io.path.getfilename.aspx

0 comments:

Post a Comment

 
Toggle Footer