c#获取文件名的方法有哪些
在C#中,获取文件名的方法有以下几种方式:
使用Path类的GetFileName方法:
string fileName = Path.GetFileName(filePath);
使用FileInfo类的Name属性:
FileInfo fileInfo = new FileInfo(filePath);
string fileName = fileInfo.Name;
使用LastIndexOf和Substring方法:
string fileName = filePath.Substring(filePath.LastIndexOf("\\") + 1);
使用正则表达式:
Regex regex = new Regex(@"[^\\]*$");
Match match = regex.Match(filePath);
string fileName = match.Value;
阅读剩余
THE END